[ https://issues.apache.org/jira/browse/THRIFT-1368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13119597#comment-13119597 ]
Bryan Duxbury commented on THRIFT-1368: --------------------------------------- You don't want to use the TNonblockingSocket on the clientside - just use TSocket. TNonblockingSocket is for NIO-based stuff. > TNonblockingServer usage > ------------------------ > > Key: THRIFT-1368 > URL: https://issues.apache.org/jira/browse/THRIFT-1368 > Project: Thrift > Issue Type: Question > Components: Java - Library > Affects Versions: 0.7 > Reporter: Jensen Li > Labels: TNonblockingServer > > Code for server side: > TNonblockingServerTransport transport = new > TNonblockingServerSocket(8888);; > AbstractNonblockingServerArgs<TNonblockingServer.Args> args = > new TNonblockingServer.Args(transport ); > args.processor(new Calculator.Processor<Iface>(new > CalculatorHandler())); > TNonblockingServer server = new TNonblockingServer(args ); > server.serve(); > Client code: > SocketAddress remote = new InetSocketAddress("localhost", 8888); > SocketChannel channel = SocketChannel.open(remote); > TNonblockingSocket tnSocket = new TNonblockingSocket(channel); > TTransport framedTransport = new > TFramedTransport.Factory().getTransport(tnSocket); > TTransport transport = framedTransport; > TProtocol protocol = new TBinaryProtocol(transport); > Calculator.Client client = new Calculator.Client(protocol); > System.out.println(client.add(1, 2)); > framedTransport.close(); > For each interface method, the first time invoking will fail, with below > exception, but later it's okay. And for multithread client, some threads may > fail with the same exception, some threads succeed, could you tell what's the > cause? > Exception: > Exception in thread "main" org.apache.thrift.transport.TTransportException: > Cannot read. Remote side has closed. Tried to read 4 bytes, but only got 0 > bytes. (This is often indicative of an internal error on the server side. > Please check your server logs.) > at org.apache.thrift.transport.TTransport.readAll(TTransport.java:86) > at > org.apache.thrift.transport.TFramedTransport.readFrame(TFramedTransport.java:129) > at > org.apache.thrift.transport.TFramedTransport.read(TFramedTransport.java:101) > at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) > at > org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) > at > org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) > at > org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:204) > at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:69) -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira