【问题标题】:C++ Thrift: Can I use TFramedTransportFactory with TThreadedServer?C++ Thrift:我可以将 TFramedTransportFactory 与 TThreadedServer 一起使用吗?
【发布时间】:2013-12-30 05:49:05
【问题描述】:

以下代码有效。

服务器:



    // 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();

客户: <pre></pre>

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();

但是,当我在服务器端使用 TBufferedTransportFactory 而不是 TFramedTransportFactory 时,它也可以正常工作。我发现使用 TThreadedServer 的唯一示例代码使用 TBufferedTransportFactory,所以我想知道 TFramedTransportFactory 是否有问题。

我切换它的原因是因为我希望一个使用 TFramedTransport 的 Java 客户端与一个使用 Java TThreadedSelectorServer 的服务器通信,也能够与这个使用 C++ TThreadedServer 的服务器通信。

【问题讨论】:

    标签: java c++ thrift transport


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2015-05-06
      • 2023-03-25
      • 2019-01-25
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 2020-08-04
      相关资源
      最近更新 更多