4

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

  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?

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

4

1 回答 1

5

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

另外需要注意的是,根据上面的示例,TNonblockingServer 将 ThreadManager 作为参数。

于 2013-08-20T14:49:24.223 回答