You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Brian Hammond <br...@brianhammond.com> on 2009/04/30 00:13:42 UTC

THttpServer in C++, THRIFT-247

Hello,

I'm playing around with THttpServer as patched in THRIFT-247.   
Actually, I am using a clone of http://github.com/ahfeel/thrift/tree/master

I'm seeing this error about the client hanging up the connection (what  
seems like to the server) unexpectedly:

> server response: 'hello there, Brian'
> Thrift: Wed Apr 29 18:09:11 2009 TSocket::peek() recv() <Host:   
> Port: 0>Connection reset by peer
> TSimpleServer client died: recv(): Connection reset by peer


I'm new to Thrift (a couple of weeks).  Anyone see something silly  
that I'm doing wrong here?

Thanks,
Brian


The .thrift file:

> namespace cpp dm
>
> service Hello {
>   string sayHello(string name);
> }


Here's a test server:

> #include "Hello.h"
> #include <protocol/TBinaryProtocol.h>
> #include <server/TSimpleServer.h>
> #include <transport/TServerSocket.h>
> #include <transport/THttpServer.h>
>
> using namespace facebook::thrift;
> using namespace facebook::thrift::protocol;
> using namespace facebook::thrift::transport;
> using namespace facebook::thrift::server;
>
> using boost::shared_ptr;
>
> using namespace dm;
>
> class HelloHandler : virtual public HelloIf {
>  public:
>   HelloHandler() {
>   }
>
>   void sayHello(std::string& ret, const std::string& name) {
>     ret = std::string("hello there, ") + name;
>   }
>
> };
>
> int main(int argc, char **argv) {
>   int port = 9090;
>   shared_ptr<HelloHandler> handler(new HelloHandler());
>   shared_ptr<TProcessor> processor(new HelloProcessor(handler));
>   shared_ptr<TServerTransport> serverTransport(new  
> TServerSocket(port));
>   shared_ptr<TTransportFactory> transportFactory(new  
> THttpServerTransportFactory());
>   shared_ptr<TProtocolFactory> protocolFactory(new  
> TBinaryProtocolFactory());
>
>   TSimpleServer server(processor, serverTransport, transportFactory,  
> protocolFactory);
>   server.serve();
>   return 0;
> }


Here's a test client:

> #include "Hello.h"
> #include <protocol/TBinaryProtocol.h>
> #include <server/TSimpleServer.h>
> #include <transport/TSocket.h>
> #include <transport/THttpClient.h>
>
> #include <string>
> #include <iostream>
>
> using namespace facebook::thrift;
> using namespace facebook::thrift::protocol;
> using namespace facebook::thrift::transport;
> using namespace facebook::thrift::server;
>
> using boost::shared_ptr;
>
> int main() {
>   shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
>   shared_ptr<TTransport> bufferedTransport(new  
> TBufferedTransport(socket));
>   shared_ptr<TTransport> transport(new  
> THttpClient(bufferedTransport, "localhost", "/"));
>   shared_ptr<TBinaryProtocol> protocol(new  
> TBinaryProtocol(transport));
>
>   dm::HelloClient client(protocol);
>
>   transport->open();
>
>   std::string response;
>   client.sayHello(response, "Brian");
>   std::cout << "server response: '" << response << "'" << std::endl;
>
>   transport->close();
>   return 0;
> }

Re: THttpServer in C++, THRIFT-247

Posted by Brian Hammond <br...@brianhammond.com>.
I tried using the TThreadPoolServer.  The server output was:

>> server response: 'hello there, Brian'
>> Thrift: Wed Apr 29 18:09:11 2009 TSocket::peek() recv() <Host:   
>> Port: 0>Connection reset by peer

The "client died" line disappeared.

These tests were performed on Mac OS X 10.5.6.


I ran the TThreadPoolServer version on Linux 2.6.18.8 (via Ubuntu) and  
it worked perfectly fine.


I suppose I'll chalk this up to Mac OS X weirdness then?


Can I ask why recv() with MSG_PEEK is used instead of select()?


Thanks,
Brian

On Apr 29, 2009, at 6:13 PM, Brian Hammond wrote:

> Hello,
>
> I'm playing around with THttpServer as patched in THRIFT-247.   
> Actually, I am using a clone of http://github.com/ahfeel/thrift/tree/master
>
> I'm seeing this error about the client hanging up the connection  
> (what seems like to the server) unexpectedly:
>
>> server response: 'hello there, Brian'
>> Thrift: Wed Apr 29 18:09:11 2009 TSocket::peek() recv() <Host:   
>> Port: 0>Connection reset by peer
>> TSimpleServer client died: recv(): Connection reset by peer
>
>
> I'm new to Thrift (a couple of weeks).  Anyone see something silly  
> that I'm doing wrong here?
>
> Thanks,
> Brian
>
>
> The .thrift file:
>
>> namespace cpp dm
>>
>> service Hello {
>>  string sayHello(string name);
>> }
>
>
> Here's a test server:
>
>> #include "Hello.h"
>> #include <protocol/TBinaryProtocol.h>
>> #include <server/TSimpleServer.h>
>> #include <transport/TServerSocket.h>
>> #include <transport/THttpServer.h>
>>
>> using namespace facebook::thrift;
>> using namespace facebook::thrift::protocol;
>> using namespace facebook::thrift::transport;
>> using namespace facebook::thrift::server;
>>
>> using boost::shared_ptr;
>>
>> using namespace dm;
>>
>> class HelloHandler : virtual public HelloIf {
>> public:
>>  HelloHandler() {
>>  }
>>
>>  void sayHello(std::string& ret, const std::string& name) {
>>    ret = std::string("hello there, ") + name;
>>  }
>>
>> };
>>
>> int main(int argc, char **argv) {
>>  int port = 9090;
>>  shared_ptr<HelloHandler> handler(new HelloHandler());
>>  shared_ptr<TProcessor> processor(new HelloProcessor(handler));
>>  shared_ptr<TServerTransport> serverTransport(new  
>> TServerSocket(port));
>>  shared_ptr<TTransportFactory> transportFactory(new  
>> THttpServerTransportFactory());
>>  shared_ptr<TProtocolFactory> protocolFactory(new  
>> TBinaryProtocolFactory());
>>
>>  TSimpleServer server(processor, serverTransport, transportFactory,  
>> protocolFactory);
>>  server.serve();
>>  return 0;
>> }
>
>
> Here's a test client:
>
>> #include "Hello.h"
>> #include <protocol/TBinaryProtocol.h>
>> #include <server/TSimpleServer.h>
>> #include <transport/TSocket.h>
>> #include <transport/THttpClient.h>
>>
>> #include <string>
>> #include <iostream>
>>
>> using namespace facebook::thrift;
>> using namespace facebook::thrift::protocol;
>> using namespace facebook::thrift::transport;
>> using namespace facebook::thrift::server;
>>
>> using boost::shared_ptr;
>>
>> int main() {
>>  shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
>>  shared_ptr<TTransport> bufferedTransport(new  
>> TBufferedTransport(socket));
>>  shared_ptr<TTransport> transport(new  
>> THttpClient(bufferedTransport, "localhost", "/"));
>>  shared_ptr<TBinaryProtocol> protocol(new  
>> TBinaryProtocol(transport));
>>
>>  dm::HelloClient client(protocol);
>>
>>  transport->open();
>>
>>  std::string response;
>>  client.sayHello(response, "Brian");
>>  std::cout << "server response: '" << response << "'" << std::endl;
>>
>>  transport->close();
>>  return 0;
>> }