title: Run tcp server in another thread
body: <p>I'm struggling with running tcp server in  different thread. So I have sth like that:</p>
  <pre><code>#include &lt;ctime&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #include &lt;boost/asio.hpp&gt;
  
  using boost::asio::ip::tcp;
  
  std::string make_daytime_string()
  {
      using namespace std; // For time_t, time and ctime;
      time_t now = time(0);
      return ctime(&amp;now);
  }
  
  class TcpServer
  {
  private:
      boost::asio::io_context&amp; io_context_;
      boost::asio::ip::tcp::acceptor acceptor_;
      boost::asio::ip::tcp::socket socket_;
      
  public:
      TcpServer(boost::asio::io_context&amp; io_context)
          : io_context_{io_context}
          , socket_(io_context_)
          , acceptor_(io_context_, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 512))
      {
          acceptor_.accept(socket_);
          std::string message = make_daytime_string();
  
          boost::system::error_code ignored_error;
          socket_.write_some(boost::asio::buffer(message), ignored_error);
      }
  };
  
  
  int main()
  {
      boost::asio::io_context io_cont;
      std::thread t([&amp;io_cont] ()
      {
          TcpServer server(io_cont);
      });
  
      std::cout &lt;&lt; &quot;I want to display it while server is still running&quot;;
  
      t.join();
      return 0;
  }
  </code></pre>
  <p>Basically this TcpServer is running all the time until it gets connection, sends datetime and then exits.
  What I want to do is:</p>
  <ol>
  <li>Run the server</li>
  <li>Keep processing my things in main function</li>
  <li>Send command <code>nc 127.0.0.1 512</code></li>
  <li>program ends</li>
  </ol>