【问题标题】:Connect two physical computers with Apache Thrift使用 Apache Thrift 连接两台物理计算机
【发布时间】:2016-05-14 10:10:49
【问题描述】:

我是 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();

【问题讨论】:

    标签: thrift


    【解决方案1】:

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

    正如 JensG 所说,使用代码:

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

    【讨论】:

    • 感谢您的回复,所以如果我的虚拟机有 ip 192.168.56.1 我需要把它放在 localhost 属性中吗?
    • @EdwinAguilar: 是的,TTransport transport = new TSocket("192.168.56.1",9090); 应该可以,因为 IP 是正确的。如果仍然无法正常工作,您可能需要检查防火墙设置。 localhost 这个名字只是一个shorthand for the local machine, or 127.0.0.1
    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 2019-08-09
    • 2021-08-04
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多