5

最近、Thrift を使用して Python を Java に接続しようとしました。

Python (PyPy) でサーバーを作成しました。動作する参照クライアントも作成しました。

次に、「接続拒否」例外のみを生成する Java クライアントを作成しました。

これの何が問題なのですか?(最近、この問題を特徴とするクローズド イシューも見つけましたhttps://issues.apache.org/jira/browse/THRIFT-1888 )

PS。Thrift 0.9 リリース、PyPy 2.0 ベータ 2、Java 1.7.0_11 を使用

テスト。倹約

namespace java com.test
namespace python test

service TestPing {
   void ping()
} 

Python サーバー コード

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.' 

Java クライアント コード

TTransport transport;
transport = new TSocket("localhost", 9091);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
client = new TestPing.Client(protocol);
client.ping();

Python クライアント コードの参照

transport = TSocket.TSocket('localhost', 9091)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = TestPing.Client(protocol)
transport.open()
client.ping()
transport.close()
4

2 に答える 2

5

I had the same issue. Replacing "localhost" with the ip fixed it.

The reason was: Python used TCPV6, where Java used TCP.

Python: transport = TSocket.TServerSocket(host="127.0.0.1", port = 9091)

Java: transport = new TSocket("127.0.0.1", 9091);

于 2014-06-05T09:20:22.283 に答える