5

Server code:

            TMultiplexedProcessor processor = new TMultiplexedProcessor();

            processor.registerProcessor(
                "AddService",
                new AddService.Processor(new AddHandler()));

            processor.registerProcessor(
                "MultiplyService",
                new MultiplyService.Processor(new MultiplyHandler()));

            TServerTransport serverTransport = new TServerSocket(7911);



            TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).
                   processor(processor));

            System.out.println("Starting server on port 7911 ...");
            server.serve();

Client Code:

    TFramedTransport transport;

   transport = new TFramedTransport(new TSocket("localhost", 7911));  
   transport.open();  


   TProtocol protocol = new TBinaryProtocol(transport);

   System.out.println("1");
   TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "AddService");
   AddService.Client service = new AddService.Client(mp);

   System.out.println("2");
   TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "MultiplyService");
   MultiplyService.Client service2 = new MultiplyService.Client(mp2);

   System.out.println("3");

   System.out.println(service.add(2,2));
   System.out.println(service2.multiply(2000,200));

But when I am running the server(listening on port 7911) and the client, the client doesnt process the last two calls to the add/multiply functions.

I could debug that the arguments have been sent to the server, but the server is not able to process them.

Any pointers as to what i am missing?

JensG
  • 13,148
  • 4
  • 45
  • 55
  • Could be helpful to know the language, especially with Thrift as a multi-language RPC framework. C#? C++? Java? System.out.println() looks like the latter ... – JensG Oct 27 '13 at 11:57
  • This is in java only.. Both the client and the server – SHUVA JYOTI KAR Oct 27 '13 at 15:56
  • Ok, what means "the server is not able to process them" exactly? Do you get an error message, or what else? – JensG Oct 27 '13 at 17:39
  • The server runs, but doesnt produce results. I have put debug statements as you can see...So the debug output is : 1 2 3 but doesnt print anything else...i have debug statements in the handler code as well but they dont appear – SHUVA JYOTI KAR Oct 28 '13 at 04:28

1 Answers1

5

Not tested, but it looks very much like as if you run two different protocol stacks on server and client. Try this:

TMultiplexedProcessor processor = new TMultiplexedProcessor();

processor.registerProcessor(
    "AddService",
    new AddService.Processor(new AddHandler()));

processor.registerProcessor(
    "MultiplyService",
    new MultiplyService.Processor(new MultiplyHandler()));

TServerTransport serverTransport = new TServerSocket(7911);

TTransportFactory factory = new TFramedTransport.Factory();

TServer.Args args = new TServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(factory);
TSimpleServer server = new TSimpleServer(args);

System.out.println("Starting server on port 7911 ...");
server.serve();
FuriousGeorge
  • 4,561
  • 5
  • 29
  • 52
JensG
  • 13,148
  • 4
  • 45
  • 55
  • Thanks a lot!! it works, but could you please point me to a link that discusses the compatiable protocaol stacks – SHUVA JYOTI KAR Oct 29 '13 at 17:29
  • 1
    That's not really complicated. The entire stack consists of (1) a protocol (2) an endpoint transport and (3) optionally additional layered transport(s). In your sample this is (1) binary protocol (2) socket transport, (3) multiplexed + framed fransports. You simply have to ensure that both sides are using the exact same mix of these ingredients. That's all. A good in-depth explanation for beginners is Randy Abernethy's forthcoming book, already partially available via MEAP: http://www.manning.com/abernethy/ – JensG Oct 29 '13 at 18:46