title: Apache Thrift server written in C++ throws TTransportException
body: <p>I'm experimenting with a very simple Apache Thrift server and client written in C++ using Visual Studio 2015. The code is based on the the official Apache Thrift samples.</p>
  
  <p>I'm using the latest version of Thrift (0.10.0), Boost (1.64.0) and OpenSSL (1.1.0e).</p>
  
  <p>Each call from the client to the server triggers a TTransportException in TTransport.h line 43:</p>
  
  <pre><code>throw TTransportException(TTransportException::END_OF_FILE, "No more data to read.");
  </code></pre>
  
  <p>Here's my test.thrift file:</p>
  
  <pre><code>namespace cpp test
  
  service Test {
      void ping()
  }
  </code></pre>
  
  <p>The thrift compiler generates Test.h which is #included below in both server and client (not showing the actual code as it's autogenerated).</p>
  
  <p>thrift header files included in both client and server:</p>
  
  <pre><code>#include &lt;thrift/protocol/TBinaryProtocol.h&gt;
  #include &lt;thrift/transport/TSocket.h&gt;
  #include &lt;thrift/transport/TTransportUtils.h&gt;
  #include &lt;thrift/server/TSimpleServer.h&gt;
  #include &lt;thrift/transport/TServerSocket.h&gt;
  #include &lt;thrift/transport/TBufferTransports.h&gt;
  
  #include &lt;Test.h&gt;
  </code></pre>
  
  <p>client main:</p>
  
  <pre><code>using namespace ::apache::thrift;
  using namespace ::apache::thrift::protocol;
  using namespace ::apache::thrift::transport;
  using namespace ::apache::thrift::server;
  
  using namespace std;
  
  int main()
  {
      boost::shared_ptr&lt;TTransport&gt; socket(new TSocket("localhost", 9090));
      boost::shared_ptr&lt;TTransport&gt; transport(new TFramedTransport(socket));
      boost::shared_ptr&lt;TProtocol&gt; protocol(new TBinaryProtocol(transport));
      test::TestClient client(protocol);
  
      try {
          transport-&gt;open();
  
          client.ping();
          cout &lt;&lt; "ping()" &lt;&lt; endl;
  
          transport-&gt;close();
      }
      catch (TException&amp; tx) {
          cout &lt;&lt; "ERROR: " &lt;&lt; tx.what() &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>and server main:</p>
  
  <pre><code>using namespace ::apache::thrift;
  using namespace ::apache::thrift::protocol;
  using namespace ::apache::thrift::transport;
  using namespace ::apache::thrift::server;
  
  using namespace std;
  
  class TestHandler : virtual public test::TestIf {
  public:
      TestHandler() {
          // Your initialization goes here
      }
  
      void ping() {
          // Your implementation goes here
          printf("ping\n");
      }
  };
  
  
  int main()
  {
      std::cout &lt;&lt; "Starting thrift server thread" &lt;&lt; std::endl;
      int port = 9090;
      boost::shared_ptr&lt;TestHandler&gt; handler(new TestHandler());
      boost::shared_ptr&lt;TProcessor&gt; processor(new test::TestProcessor(handler));
      boost::shared_ptr&lt;TServerTransport&gt; serverTransport(new TServerSocket(port));
      boost::shared_ptr&lt;TTransportFactory&gt; transportFactory(new TFramedTransportFactory());
      boost::shared_ptr&lt;TProtocolFactory&gt; protocolFactory(new TBinaryProtocolFactory());
  
      boost::shared_ptr&lt; apache::thrift::server::TSimpleServer &gt; server = boost::shared_ptr&lt; TSimpleServer&gt;(new TSimpleServer(processor, serverTransport, transportFactory, protocolFactory));
  
      server-&gt;serve();
      return 0;
  }
  </code></pre>
  
  <p>I also tried using TBufferedTransport and TJSONProtocol with the same result.</p>
  
  <p>The fact that an exception is thrown indicates that this is not normal functioning, however, the call is received and processed (the exception happens after the call to TestHandler::ping()) and the server continues to listen to and receive requests (triggering the same error each time), so it is a recoverable condition. </p>
  
  <p>So I'm wondering why this is happening, is it something that can/should be fixed, and how, and if not, is it safe to use the server despite this exception.</p>