节俭的客户呼叫服务器,客户可以成功接收结果,但是服务出现异常
服务器
TServerSocket serverTransport = new TServerSocket(9090);
TBinaryProtocol.Factory proFactory = new TBinaryProtocol.Factory();
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor(
RPCService.class.getSimpleName(),
new RPCService.Processor<RPCService.Iface>(new RPCServiceImpl())
);
processor.registerProcessor(
RPCService2.class.getSimpleName(),
new RPCService2.Processor<RPCService2.Iface>(new RPCService2Impl())
);
TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
serverArgs.processor(processor);
serverArgs.protocolFactory(proFactory);
TServer server = new TThreadPoolServer(serverArgs);
System.out.println("Start server on port 9090...");
server.serve();
客户
public static void startClient() {
TTransport transport;
try {
transport = new TSocket("localhost", 9090);
TProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol mp1 = new TMultiplexedProtocol(protocol, RPCService.class.getSimpleName());
TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, RPCService2.class.getSimpleName());
RPCService.Client client1 = new RPCService.Client(mp1);
RPCService2.Client client2 = new RPCService2.Client(mp2);
transport.open();
boolean loginResult = client1.login("aa","111");
boolean loginResult2 = client2.login2("bb","222");
System.out.println(loginResult+""+loginResult2);
transport.close();
}
错误:
14:22:30.914 [pool-1-thread-1] ERROR org.apache.thrift.server.TThreadPoolServer
- Thrift error occurred during processing of message.
org.apache.thrift.transport.TTransportException: null
at org.apache.thrift.transport.TIOStreamTransport.read(TIOStreamTransport.java:132)
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86)
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:425)
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:321)
at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:225)
at org.apache.thrift.TMultiplexedProcessor.process(TMultiplexedProcessor.java:101)
at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)