本文整理汇总了C++中tcp::acceptor::accept方法的典型用法代码示例。如果您正苦于以下问题:C++ acceptor::accept方法的具体用法?C++ acceptor::accept怎么用?C++ acceptor::accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::acceptor
的用法示例。
在下文中一共展示了acceptor::accept方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getClientConnection
void getClientConnection (tcp::acceptor &acceptor) {
std::cout << "In GUIMessageSenderThread getClientConnection()" << std::endl;
try
{
std::cout << "waiting for gui client to connect..." << std::endl;
acceptor.accept(*stream_.rdbuf());
std::cout << "...gui client connected" << std::endl;
connected_ = true;
}
catch (std::exception& e)
{
std::cerr << "Error in gui client connection: " << e.what() << std::endl;
}
std::cout << "done GUIMessageSenderThread getClientConnection()" << std::endl;
}
示例2: acceptorLoop
void acceptorLoop()
{
cout << "Waiting for clients..." << endl;
for(;;)
{
socket_ptr clientSock(new tcp::socket(service));
acceptor.accept(*clientSock);
cout << "New client joined! ";
mtx.lock();
clientList->emplace_back(clientSock);
mtx.unlock();
cout << clientList->size() << " total clients" << endl;
}
}