You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by sergiu F <fs...@yahoo.com> on 2012/03/23 14:57:00 UTC

how to have two protocols on same TServerSocket?

Hi,

It is possible to have two kind of protocols mapped on same port? For example this code accept clients having json and binary. Code works fine only if requests from clients come in same order: json,binary,json,binary....

thanks
serj

            TServerSocket serverTransport = new TServerSocket(7912);
            TJSONProtocol.Factory f = new TJSONProtocol.Factory();
            
            TimeServer.Processor processor = new TimeServer.Processor(new TimeServerImpl());
            final TServer jsonServer = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).
                    processor(processor).protocolFactory(f));

            final TServer binaryServer = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
            
            new Thread(new Runnable(){
                @Override
                public void run() {
                    System.out.println("Starting serverJSON on port 7912 ...");
                    jsonServer.serve();
                }
                
            }).start();

            new Thread(new Runnable(){
                @Override
                public void run() {
                    System.out.println("Starting serverBINARY on port 7912 ...");
                    binaryServer.serve();
                }
                
            }).start();

Re: AW: how to have two protocols on same TServerSocket?

Posted by sergiu F <fs...@yahoo.com>.

Thank you for your answer.

How can I use guessProtocolFactory? From what I see in thrift source code, the only way to accept any protocol is to create my own class that extends org.apache.thrift.protocol.TProtocol. I think detecting protocol can be done in readMessageBegin() method.

Is there any other way to use guessProtocolFactory?

Best regards
serj

AW: how to have two protocols on same TServerSocket?

Posted by Roger Meier <ro...@bufferoverflow.ch>.
Hi

Java implementation provides guessProtocolFactory ==> server can support
json and binary

-roger

> -----Ursprüngliche Nachricht-----
> Von: sergiu F [mailto:fserj@yahoo.com]
> Gesendet: Freitag, 23. März 2012 14:57
> An: user@thrift.apache.org
> Betreff: how to have two protocols on same TServerSocket?
> 
> 
> Hi,
> 
> It is possible to have two kind of protocols mapped on same port? For
> example this code accept clients having json and binary. Code works fine
only
> if requests from clients come in same order: json,binary,json,binary....
> 
> thanks
> serj
> 
>             TServerSocket serverTransport = new TServerSocket(7912);
>             TJSONProtocol.Factory f = new TJSONProtocol.Factory();
> 
>             TimeServer.Processor processor = new TimeServer.Processor(new
> TimeServerImpl());
>             final TServer jsonServer = new TThreadPoolServer(new
> TThreadPoolServer.Args(serverTransport).
>                     processor(processor).protocolFactory(f));
> 
>             final TServer binaryServer = new TThreadPoolServer(new
> TThreadPoolServer.Args(serverTransport).processor(processor));
> 
>             new Thread(new Runnable(){
>                 @Override
>                 public void run() {
>                     System.out.println("Starting serverJSON on port 7912
...");
>                     jsonServer.serve();
>                 }
> 
>             }).start();
> 
>             new Thread(new Runnable(){
>                 @Override
>                 public void run() {
>                     System.out.println("Starting serverBINARY on port 7912
...");
>                     binaryServer.serve();
>                 }
> 
>             }).start();