Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to launch an "event" when my Boost::asio tcp server just start running ( AKA io_service.run() )?
    primarykey
    data
    text
    <p>Based on an boost::asio client/server relationship, I have to launch the client program from the server program only when the server thread is in a "<strong>waiting to be connected</strong>" state.<br> <br/> My question is how to have the knowledge of that state ? <br/></p> <p>As a sample use the <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/example/serialization/" rel="nofollow">asio example/serialization</a> <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/example/serialization/" rel="nofollow">link</a>, and replace the main function of server.cpp with that code:</p> <pre><code>#include &lt;conio.h&gt; #include &lt;concrt.h&gt; // wait function #include &lt;future&gt; #include &lt;thread&gt; void server_thread( std::promise&lt;bool&gt;&amp; run ) { boost::asio::io_service io_service; s11n_example::server server(io_service, 123); // too early to run.set_value( true ); io_service.run(); // too late to run.set_value( true ); } int main(int argc, char* argv[]) { std::promise&lt;bool&gt; run; std::thread thrd( server_thread, boost::ref( run ) ); thrd.detach(); bool launched = run.get_future().get(); // server is waiting for connection // launch the client if( launched ) { int rc = system( "start client.exe localhost 123" ); if( rc ) std::cerr &lt;&lt; "system failed returning " &lt;&lt; rc &lt;&lt; std::endl ; } else std::cerr &lt;&lt; "server_thread failure" &lt;&lt; std::endl ; std::cout &lt;&lt; "hit a key to exit" ; while( !_kbhit() ) Concurrency::wait( 100 ); return 0; } </code></pre> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload