如何通过thrift客户端连接到远程thrift服务器

时间:2014-01-29 08:53:23

标签: thrift

我在thrift中创建了一个服务器和一个客户端。然后我在计算机上启动了thrift服务器。我使用我的机器IP地址在局域网中的另一台计算机上运行客户端。

public class ArithmeticClient {

private void invoke() {
    TTransport transport;
    try {
        transport = new TSocket("192.168.0.232"/*this is my machine,which the sever runs' IP address*/, 7911);

        TProtocol protocol = new TBinaryProtocol(transport);

        ArithmeticService.Client client = new ArithmeticService.Client(protocol);
        transport.open();

        long addResult = client.add(100, 200);
        System.out.println("Add result: " + addResult);
        long multiplyResult = client.multiply(20, 40);
        System.out.println("Multiply result: " + multiplyResult);

        transport.close();
    } catch (TTransportException e) {
        e.printStackTrace();
    } catch (TException e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    ArithmeticClient c = new ArithmeticClient();
    c.invoke();
}

}

我收到了错误

    org.apache.thrift.transport.TTransportException: java.net.NoRouteToHostException: No route to host
    at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
    at ArithmeticClient.invoke(ArithmeticClient.java:18)
    at ArithmeticClient.main(ArithmeticClient.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.net.NoRouteToHostException: No route to host
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at org.apache.thrift.transport.TSocket.open(TSocket.java:180)
    ... 7 more

我该如何解决这个问题。

两台电脑都运行Fedora。版本不同(17和19)

1 个答案:

答案 0 :(得分:1)

  

公共类NoRouteToHostException扩展SocketException

     

表示尝试连接套接字时发生错误   远程地址和端口。通常,远程主机不能   因为介入防火墙或中间人而达到了   路由器坏了。

the docs说的是什么,以及我猜的是什么。这可能是原因吗?如果您尝试ping或telnet该计算机会发生什么?