title: Apache Thrift Python-Java 'Connection Refused'
body: <p>I've recently tried to connect Python to Java using Thrift.</p>
  
  <p>I've written a server on Python (PyPy). I've also written a reference client which works.</p>
  
  <p>Then I've written a Java client which produces only a 'Connection refused' exception.</p>
  
  <p>What's wrong with this? (Recently I've also found a closed issue featuring this problem <a href="https://issues.apache.org/jira/browse/THRIFT-1888" rel="noreferrer">https://issues.apache.org/jira/browse/THRIFT-1888</a>)</p>
  
  <p>PS. Used Thrift 0.9 release, PyPy 2.0 beta 2, Java 1.7.0_11</p>
  
  <p><em>test.thrift</em></p>
  
  <pre><code>namespace java com.test
  namespace python test
  
  service TestPing {
     void ping()
  } 
  </code></pre>
  
  <p><em>Python server code</em></p>
  
  <pre><code>class TestPingHandler:
    def ping(self):
      pass
  
  handler = TestPingHandler()
  processor = TestPing.Processor(handler)
  transport = TSocket.TServerSocket(port=9091)
  tfactory = TTransport.TBufferedTransportFactory()
  pfactory = TBinaryProtocol.TBinaryProtocolFactory()
  
  server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
  
  print 'Starting the server...' 
  server.serve()
  print 'done.' 
  </code></pre>
  
  <p><em>Java client code</em></p>
  
  <pre><code>TTransport transport;
  transport = new TSocket("localhost", 9091);
  transport.open();
  TProtocol protocol = new TBinaryProtocol(transport);
  client = new TestPing.Client(protocol);
  client.ping();
  </code></pre>
  
  <p><em>Reference Python client code</em></p>
  
  <pre><code>transport = TSocket.TSocket('localhost', 9091)
  transport = TTransport.TBufferedTransport(transport)
  protocol = TBinaryProtocol.TBinaryProtocol(transport)
  client = TestPing.Client(protocol)
  transport.open()
  client.ping()
  transport.close()
  </code></pre>