Search code examples
thrift

Connect two physical computers with Apache Thrift


I am new to Apache Thrift and I am in a college project where I need to connect a C++ server and a C# client with Apache Thrift.

I can connect both of them when they are running in the same PC. From the beginning, the tutorial with:

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

But I need to separate them, one in a PC running Linux and the another in a Windows-running PC, so both of them are in the same network. How or where do I need to configure to make this happen?

To be more specific: The main PC is running Windows and inside is a virtual machine running Ubuntu 16.04 which has a running C++ server with:

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

Solution

  • "localhost" specifies that the client will connect to the server on the same machine. First open a command prompt on the Windows machine and make sure ping 192.168.56.1 works.

    As JensG said, use the code:

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