thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Hammond <br...@brianhammond.com>
Subject THttpServer in C++, THRIFT-247
Date Wed, 29 Apr 2009 22:13:42 GMT
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;
> }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message