本文整理汇总了C++中TcpServer::prepare_server_socket方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::prepare_server_socket方法的具体用法?C++ TcpServer::prepare_server_socket怎么用?C++ TcpServer::prepare_server_socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpServer
的用法示例。
在下文中一共展示了TcpServer::prepare_server_socket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Create an instance of the server
TcpServer server = TcpServer::create_server();
// Prepare the server for listening for client connections
char* port_str = (char*) "2013"; // default port 2013
if (argc == 2) {
port_str = (char*) argv[1];
}
unsigned short port = (unsigned short) atoi(port_str);
int server_fd = server.prepare_server_socket(port, SOCK_STREAM);
if (server_fd == -1) {
cout << "Server preparation failed. Exiting application..." << endl;
exit(1);
}
// Run the main loop
// This method run indefinitely
int ret = server.run_main_event_loop();
if (ret != 0) {
cout << "Error running the server main event loop, exiting the server process..." << endl;
}
// At this point we are exiting the server
return 0;
}