我最近試圖使用Thrift將Python連接到Java。Apache Thrift Python-Java'Connection Refused'
我已經在Python(PyPy)上編寫了一個服務器。我還寫了一個可以工作的參考客戶端。
然後我寫了一個Java客戶端,它只產生一個'連接被拒絕'異常。
這是怎麼回事? (最近我也發現了一個特寫問題https://issues.apache.org/jira/browse/THRIFT-1888)
PS。二手舊貨0.9版本,PyPy 2.0 beta 2版本,Java的1.7.0_11
test.thrift
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()
還不行 – 43l0v3k