本文整理汇总了C++中TCPStream::getPeerIP方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPStream::getPeerIP方法的具体用法?C++ TCPStream::getPeerIP怎么用?C++ TCPStream::getPeerIP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPStream
的用法示例。
在下文中一共展示了TCPStream::getPeerIP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
int conn_timeout = 10, rw_timeout = 0;
// As of now this is to choose the server to connect to
if(argc != 3){
printf("Usage: server <port> [<ip>]\n");
exit(1);
}
TCPStream* stream = NULL;
TCPAcceptor* acceptor = NULL;
acceptor = new TCPAcceptor(atoi(argv[1]), argv[2]);
// This is hard coded to the server thats running the redis server
acl::string addr("135.44.219.148:6380");
acl::acl_cpp_init();
acl::log::stdout_open(true);
acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
acl::redis_pubsub redis(&client);
// Hard coded channel
acl::string channel = "channel", msg;
redis.clear();
// Have this program run continuously, and if an ip address is picked up, publish it to the redis server
if (acceptor->start() == 0) {
while (1) {
stream = acceptor->accept();
if (stream != NULL) {
printf("IP %s\n", stream->getPeerIP().c_str());
msg.format("%s", stream->getPeerIP().c_str());
redis.publish(channel, msg, msg.length());
}
}
}
#ifdef WIN32
printf("enter any key to exit\r\n");
getchar();
#endif
return 0;
}