thrift:从tSimpleServer更改为TNonblockingServer

时间:2013-08-20 14:37:51

标签: c++ connection thrift

我有一个简单的节俭服务器:

  shared_ptr<TProcessor> processor(new MyProcessor(handlerTrace));
  shared_ptr<TServerTransport>  serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory>  protocolFactory(new TBinaryProtocolFactory());

  TSimpleServer server(processor, serverTransport,
               transportFactory, protocolFactory);

并且能够连接以下行:

   boost::shared_ptr<TSocket> socket(new TSocket("localhost", port));
   boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
   boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

   MyClient client(protocol);

现在我想将服务器更改为TNonblockingServer。因此,我将服务器代码更改为以下内容:

  shared_ptr<TServerTransport>  serverTransport(new TServerSocket(port));
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
  TNonblockingServer server(processor,
                protocolFactory,
                port);

客户端未更改。现在服务器抱怨客户端时出现以下错误消息:

Thrift: Mon Aug 19 22:55:43 2013 TNonblockingServer: Serving on port 9990, 1 io threads.
Thrift: Mon Aug 19 22:55:43 2013 TNonblockingServer: using libevent 2.0.16-stable method epoll
Thrift: Mon Aug 19 22:55:43 2013 TNonblocking: IO thread #0 registered for listen.
Thrift: Mon Aug 19 22:55:43 2013 TNonblocking: IO thread #0 registered for notify.
Thrift: Mon Aug 19 22:55:43 2013 TNonblockingServer: IO thread #0 entering loop...
Thrift: Mon Aug 19 22:55:48 2013 TNonblockingServer: frame size too large (2147549185 > 268435456) from client <Host: 127.0.0.1 Port: 57130>. Remote side not using TFramedTransport?

我做错了什么?评论?我正在使用1.0-dev版本的thrift,因为只有这个版本支持多路复用..

1 个答案:

答案 0 :(得分:3)

尝试在客户端使用TFramedTransport而不是TBufferedTransport。 请看这个例子:http://wiki.apache.org/thrift/ThriftUsageC%2B%2B

另一件值得注意的事情是,根据上面的示例,TNonblockingServer将ThreadManager作为参数。