本文整理汇总了C++中Address::getHost方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::getHost方法的具体用法?C++ Address::getHost怎么用?C++ Address::getHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getHost方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receive
int NetworkedClient::receive(int timeout){
char buf[NETWORKED_MODULE_RECEIVE_BUFFER_SIZE];
Address remote;
int size=socket.recvFrom(remote, buf, NETWORKED_MODULE_RECEIVE_BUFFER_SIZE, timeout);
// std::cout << __PRETTY_FUNCTION__ << "begin" << std::endl;
if (remote.getHost()==0xffffffff){
// std::cout << __PRETTY_FUNCTION__ << " broadcast HOST" << std::endl;
elapsedTimeoutReceived();
return 0;
} else {
PeerInfoMap::iterator peer=peers.find(remote);
if (peer==peers.end()){
PeerInfo pinfo;
peers.insert(std::make_pair(remote,pinfo));
peer=peers.find(remote);
std::cout << "registering supplier HOST= " <<remote.getHost() << " port=" << remote.getPort() <<std::endl;
}
gettimeofday(&peer->second.lastPingTime, 0);
socket.sendTo(remote,"",0);
// std::cout << "Parsing" << std::endl;
if (size)
parseMessage(size, buf);
return size;
}
}
示例2: resolve
Address Resolver::resolve(const Address &cInfo)
{
string addrOut;
const char *addr=cInfo.getHost().c_str();
if( strcmp(addr, "*")==0 ) // all addresses?
addrOut="0.0.0.0"; // addr-any
else
{
if( inet_addr(addr)==INADDR_NONE ) // non-IP?
{
// if everyting fails - try DNS:
struct hostent *dns_info=gethostbyname(addr);
if(dns_info==NULL || dns_info->h_addr_list[0]==NULL) // no match?
throw Exception("Resolver::resolve(): unknown host '" +
cInfo.getHost() + "'");
// choose first from the list...
const in_addr *inAddr=reinterpret_cast<in_addr*>(
dns_info->h_addr_list[0]);
const char *tab =inet_ntoa(*inAddr);
addrOut=string(tab);
}
else // if(non-IP)
{
// so this is a correct address!
addrOut=cInfo.getHost();
};
}; // else(addr=="*")
// returned resolved host info
Address resolved(addrOut, cInfo.getPort() );
return resolved;
};
示例3: operator
bool addressComparator::operator ()(const Address &lhs, const Address &rhs) const {
int i = lhs.getHost().compare(rhs.getHost());
if (i == 0) {
return lhs.getPort() > rhs.getPort();
}
return i > 0;
}
示例4: multicastServer
void multicastServer()
{
char buffer[6];
DgramSocket sock;
Address client;
cout << "Dgram multicast server: Start" << endl;
sock.open();
sock.setReusePort(true);
sock.bind(AnyAddress(23344));
sock.join(Address("224.0.0.50"));
sock.join(Address("224.0.0.52"));
sock.join(Address("224.0.0.53"));
sock.leave(Address("224.0.0.52"));
do
{
sock.recvFrom(buffer,6,client);
sock.sendTo(buffer,6,client);
cout << client.getHost() << " " << buffer << endl;
} while(strcmp(buffer,"_END_"));
sock.close();
cout << "Dgram multicast server: OK" << endl;
}
示例5: calculateDataSize
int AddressCodec::calculateDataSize(const Address &address) {
return ClientMessage::calculateDataSize(address.getHost()) + ClientMessage::INT32_SIZE;
}
示例6: encode
void AddressCodec::encode(const Address &address, ClientMessage &clientMessage) {
clientMessage.set(address.getHost());
clientMessage.set((int32_t)address.getPort());
}