我正在使用Apache Thrift版本0.11编写示例客户端和服务器。但是,当从服务器调用方法时,它将引发TFramedTransport异常:错误AbstractNonblockingServer $ FrameBuffer:348-读取无效的帧大小为-2147418111。您在客户端上使用TFramedTransport吗?
这是我的客户代码:
public static ResourceManagerClient getNewClient(String host, int port){
//create client socket connect to server
TSocket clientSocket = new TSocket(host, port);
clientSocket.setTimeout(TIME_OUT);
//define transport and protocol
TFramedTransport transport = new TFramedTransport(clientSocket);
TBinaryProtocol protocol = new TBinaryProtocol(clientSocket);
ResourceService.Client instance = new ResourceService.Client(protocol);
ResourceManagerClient client = new ResourceManagerClient(instance, transport);
return client;
}
和服务器源代码:
public static void main(String[] args) {
System.out.println("Starting server ...");
try{
//init service processor
ResourceServiceImp handler = new ResourceServiceImp();
ResourceService.Processor processor = new ResourceService.Processor(handler);
//define transport type
TFramedTransport.Factory transport = new TFramedTransport.Factory();
//define protocol
TBinaryProtocol.Factory protocol = new TBinaryProtocol.Factory();
// init nonblocking socket server with default address is localhost
TNonblockingServerSocket socket = new TNonblockingServerSocket(ServerConfig.PORT);
//init server Args
THsHaServer.Args serverArgs = new THsHaServer.Args(socket)
.processor(processor)
.transportFactory(transport)
.inputTransportFactory(new TFramedTransport.Factory())
.outputTransportFactory(new TFramedTransport.Factory())
.protocolFactory(protocol);
TServer server = new THsHaServer(serverArgs);
System.out.println("Server is started. Listening on: "+ServerConfig.PORT);
//start server
server.serve();
}catch(TTransportException ex){
m_logger.error("Can not start server! Exception: " + ex.getMessage());
}
}
当我从客户端调用方法时发生异常:
2018-07-25 15:38:01 ERROR AbstractNonblockingServer$FrameBuffer:348 - Read an invalid frame size of -2147418111. Are you using TFramedTransport on the client side?
感谢您的帮助!