1. 程式人生 > >關於java通過thrift呼叫介面,客戶端丟擲org.apache.thrift.transport.TTransportException

關於java通過thrift呼叫介面,客戶端丟擲org.apache.thrift.transport.TTransportException

經測試研究,應該是協議問題,

public void startClient(String username) {
        TTransport tTransport = null;
        try {
            tTransport = new TSocket(SERVER_IP, SERVER_PORT);
            TTransport transport = new TFramedTransport(tTransport);
            //協議要和服務端一致
            TProtocol protocol = new TBinaryProtocol(transport);
            HelloWorldService.Client client = new HelloWorldService.Client(protocol);
            tTransport.open();

            String result = client.sayHello(username);
            System.out.println("Thrift client result=" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

根據伺服器端分析 ,新增程式碼:TTransport transport = new TFramedTransport(tTransport);

測試,通過。