Details

      Description

      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)

        Activity

        Hide
        Bryan Duxbury added a comment -

        You don't want to use the TNonblockingSocket on the clientside - just use TSocket. TNonblockingSocket is for NIO-based stuff.

        Show
        Bryan Duxbury added a comment - You don't want to use the TNonblockingSocket on the clientside - just use TSocket. TNonblockingSocket is for NIO-based stuff.

          People

          • Assignee:
            Unassigned
            Reporter:
            Jensen Li
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development