2

The following code works.

Server:



    // SampleServiceHandler is a class that implements 
    // the Thrift service methods.
    shared_ptr handler(new SampleServiceHandler);
    shared_ptr processor(new SampleServiceProcessor(handler));
    shared_ptr serverTransport(
       new transport::TServerSocket(serverPort));
    shared_ptr transportFactory(
       new transport::TFramedTransportFactory());
    shared_ptr protFactory(
       new protocol::TBinaryProtocolFactory());
    shared_ptr server(new server::TThreadedServer(
       processor, serverTransport, transportFactory, protFactory));
    server->serve();

Client:

shared_ptr<TSocket> socket(new TSocket(serverName, serverPort));
shared_ptr<TTransport> transport(new TFramedTransport(socket));
shared_ptr<protocol::TProtocol> protocol(
   new protocol::TBinaryProtocol(transport));
shared_ptr<ThriftClient> client(new SampleServiceClient(protocol));
transport->open();
client->sampleThriftMethod();

However, it was also working before when I was using TBufferedTransportFactory instead of TFramedTransportFactory on the server side. The only sample code I've found for using TThreadedServer uses TBufferedTransportFactory, so I'm wondering if there's something wrong with TFramedTransportFactory.

The reason I switched it is because I want a Java client that uses TFramedTransport to talk to a Java TThreadedSelectorServer-using server to also be able to talk to this C++ TThreadedServer-using server.

4

1 回答 1

0

TFramedTransport使用时在 C++ lib 中是必需的TNonblockingServer(类似于 Java TThreadedSelectorServer)。

在其他情况下,它是可选的,但它会起作用。它没有在示例中使用,是那些使用 TThreadedServer 的示例。

仍然 - 您的设置没有问题。

于 2015-05-05T09:30:34.447 回答