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

Connect two physical computers with Apache Thrift

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

当它们 运行 在同一台电脑上时,我可以连接它们。从一开始,教程有:

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

但我需要将它们分开,一个在PC 运行 Linux 中,另一个在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();

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

正如JensG所说,使用代码:

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