| 94 | //------------------------------------------------------------------------------ |
| 95 | |
| 96 | int |
| 97 | main(int argc, char** argv) |
| 98 | { |
| 99 | try |
| 100 | { |
| 101 | // Check command line arguments. |
| 102 | if(argc != 4) |
| 103 | { |
| 104 | std::cerr |
| 105 | << "Usage: websocket-client-awaitable <host> <port> <text>\n" |
| 106 | << "Example:\n" |
| 107 | << " websocket-client-awaitable echo.websocket.org 80 \"Hello, world!\"\n"; |
| 108 | return EXIT_FAILURE; |
| 109 | } |
| 110 | auto const host = argv[1]; |
| 111 | auto const port = argv[2]; |
| 112 | auto const text = argv[3]; |
| 113 | |
| 114 | // The io_context is required for all I/O |
| 115 | net::io_context ioc; |
| 116 | |
| 117 | // Launch the asynchronous operation |
| 118 | net::co_spawn( |
| 119 | ioc, |
| 120 | do_session(host, port, text), |
| 121 | [](std::exception_ptr e) |
| 122 | { |
| 123 | if(e) |
| 124 | std::rethrow_exception(e); |
| 125 | }); |
| 126 | |
| 127 | // Run the I/O service. The call will return when |
| 128 | // the socket is closed. |
| 129 | ioc.run(); |
| 130 | } |
| 131 | catch(std::exception const& e) |
| 132 | { |
| 133 | std::cerr << "Error: " << e.what() << std::endl; |
| 134 | return EXIT_FAILURE; |
| 135 | } |
| 136 | return EXIT_SUCCESS; |
| 137 | } |
| 138 | |
| 139 | #else |
| 140 |
nothing calls this directly
no test coverage detected