使用Apache Thrift连接两台物理计算机

时间:2016-05-14 10:10:49

标签: thrift

我是Apache Thrift的新手,我在一个大学项目中,我需要将一个C ++服务器和一个C#客户端连接到Apache Thrift。

当他们在同一台PC上运行时,我可以连接它们。从一开始,教程就是:

TTransport transport = new TSocket("localhost",9090);
TProtocol protocol = new TBinaryProtocol(transport);
Analizador.Client client = new Analizador.Client(protocol);

但是我需要将它们分开,一个在运行Linux的PC中,另一个在运行Windows的PC中,因此它们都在同一个网络中。我需要配置如何或在哪里实现这一目标?

更具体一点:主PC正在运行Windows,内部是运行Ubuntu 16.04的虚拟机,它有一个正在运行的C ++服务器:

int port = 9090;
shared_ptr<AnalizadorHandler> handler(new AnalizadorHandler());
shared_ptr<TProcessor> processor(new AnalizadorProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();

1 个答案:

答案 0 :(得分:2)

"localhost"指定客户端将连接到同一台计算机上的服务器。首先在Windows计算机上打开命令提示符,确保ping 192.168.56.1正常工作。

正如JensG所说,使用代码:

TTransport transport = new TSocket("192.168.56.1", 9090);