MCPcopy Create free account
hub / github.com/boostorg/beast / main

Function main

example/websocket/server/sync/websocket_server_sync.cpp:81–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79//------------------------------------------------------------------------------
80
81int main(int argc, char* argv[])
82{
83 try
84 {
85 // Check command line arguments.
86 if (argc != 3)
87 {
88 std::cerr <<
89 "Usage: websocket-server-sync <address> <port>\n" <<
90 "Example:\n" <<
91 " websocket-server-sync 0.0.0.0 8080\n";
92 return EXIT_FAILURE;
93 }
94 auto const address = net::ip::make_address(argv[1]);
95 auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
96
97 // The io_context is required for all I/O
98 net::io_context ioc{1};
99
100 // The acceptor receives incoming connections
101 tcp::acceptor acceptor{ioc, {address, port}};
102 for(;;)
103 {
104 // This will receive the new connection
105 tcp::socket socket{ioc};
106
107 // Block until we get a connection
108 acceptor.accept(socket);
109
110 // Launch the session, transferring ownership of the socket
111 std::thread(
112 &do_session,
113 std::move(socket)).detach();
114 }
115 }
116 catch (const std::exception& e)
117 {
118 std::cerr << "Error: " << e.what() << std::endl;
119 return EXIT_FAILURE;
120 }
121}

Callers

nothing calls this directly

Calls 4

threadClass · 0.85
moveClass · 0.85
whatMethod · 0.80
acceptMethod · 0.45

Tested by

no test coverage detected