本文整理汇总了C++中Tcp::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ Tcp::Bind方法的具体用法?C++ Tcp::Bind怎么用?C++ Tcp::Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tcp
的用法示例。
在下文中一共展示了Tcp::Bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
{
MyTimeoutHandler timeoutHandler;
SignalHandler signalHandler;
Signal *signal = Signal::New();
timeoutHandler.AddHandle(signal);
assert(! signal->Start(SIGINT, signalHandler));
signal->Unref();
signal = Signal::New();
timeoutHandler.AddHandle(signal);
assert(! signal->Start(SIGTERM, signalHandler));
signal->Unref();
Server serverEventHandler(timeoutHandler);
Tcp *server = Tcp::New();
timeoutHandler.AddHandle(server);
assert(! server->Bind(Ip4Address("0.0.0.0", 1234)));
assert(! server->Listen(serverEventHandler));
server->Unref();
Client clientEventHandler;
Tcp *client = Tcp::New();
timeoutHandler.AddHandle(client);
assert(! client->Connect(Ip4Address("127.0.0.1", 1234), &clientEventHandler));
client->Unref();
PingPeer peer1("Peer1");
Udp *endPoint1 = Udp::New();
assert(endPoint1);
timeoutHandler.AddHandle(endPoint1);
assert(! endPoint1->Bind(Ip4Address("0.0.0.0", 1357)));
assert(! endPoint1->RecvStart(peer1));
PingPeer peer2("Peer2");
Udp *endPoint2 = Udp::New();
assert(endPoint2);
timeoutHandler.AddHandle(endPoint2);
assert(! endPoint2->Bind(Ip4Address("0.0.0.0", 2468)));
assert(! endPoint2->RecvStart(peer2));
Buffer *buf = new Buffer("Hello");
assert(! endPoint1->Send(*buf, Ip4Address("127.0.0.1", 2468)));
buf->Unref();
buf = new Buffer("World");
assert(! endPoint2->Send(*buf, Ip4Address("127.0.0.1", 1357)));
buf->Unref();
endPoint1->Unref();
endPoint2->Unref();
Timer *timer = Timer::New();
timeoutHandler.AddHandle(timer);
assert(timer);
assert(! timer->Start(1000, timeoutHandler));
timer->Unref();
Loop::Run();
timeoutHandler.CloseHandles();
Loop::Free();
}
cout << Handle::count << " handle alive" << endl;
return 0;
}