title: boost::tcp::iostream read & write simultaneously
body: <p>I wish to implement a full-duplex tcp stream. Here is an example.</p>
  
  <pre><code>//server.cpp
  
  #include &lt;SDKDDKVer.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  
  boost::asio::ip::tcp::iostream SocketStream;
  
  void ThreadA()
  {
      for(;;)
      {
          std::string Line;
          std::getline(SocketStream, Line);    //Y
          std::cout &lt;&lt; Line &lt;&lt; std::endl;
      }
  }
  
  void ThreadB()
  {
      for(;;)
      {
          std::string Line;
          std::getline(std::cin, Line);     //Z
          SocketStream&lt;&lt;Line&lt;&lt;std::endl;    //X
      }
  }
  
  int main()
  {  
      boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 4444);
      boost::asio::io_service io_service;
      boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint);
      boost::system::error_code ec;
      acceptor.accept(*SocketStream.rdbuf(), ec);
  
      boost::thread tA(ThreadA);
      boost::thread tB(ThreadB);
      tA.join(); 
      tB.join();
      return 0;
  }
  
  //client.cpp
  
  #include &lt;SDKDDKVer.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  
  
  boost::asio::ip::tcp::iostream SocketStream;
  
  void ThreadA()
  {
      for(;;)
      {
          std::string Line;
          std::getline(SocketStream, Line);    
          std::cout &lt;&lt; Line &lt;&lt; std::endl;
      }
  }
  
  void ThreadB()
  {
      for(;;)
      {
          std::string Line;
          std::getline(std::cin, Line);     
          SocketStream&lt;&lt;Line&lt;&lt;std::endl;    
      }
  }
  
  int main()
  {  
      boost::system::error_code ec;
      SocketStream.connect("127.0.0.1", "4444");
  
      boost::thread tA(ThreadA);
      //boost::thread tB(ThreadB);
      tA.join(); 
      //tB.join();
      return 0;
  }
  </code></pre>
  
  <p>But it would block on line X.<br>
  <strong>Q1</strong>, am I doing something wrong or is <code>boost::asio::ip::tcp::iostream</code> simply incapable of doing this?<br>
  <strong>Q2</strong>, if <code>boost::asio::ip::tcp::iostream</code> is not enough to fulfill the mission, what else should I use?<br>
  I saw <code>boost::iostream</code> having a bidirectional mode. Is that what I'm looking for? I'm unfamiliar with <code>boost::iostream</code> so I'm not sure what it really does.<br>
  If <code>boost::iostream</code> fails too, then must I use <code>boost::asio</code>'s asynchronous operations? Cuz what I want is to make the socket really behave like a stream and wrapping asynchronous operations may be difficult.</p>
  
  <p><strong>Additional:</strong> What I wish is that the <code>SocketStream</code> can be written while it's also blocking at reading, which means that the stream is full-duplex.</p>
  
  <p>Please, any advice would be appreciated!</p>