thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger Meier <ro...@bufferoverflow.ch>
Subject Re: C++ server won't accept connections, java server will
Date Mon, 29 Apr 2013 18:38:26 GMT
test/test.sh does cross language tests and might be a look worth

what protocol do you use on php side?

;-r

Quoting Matthew Mucker <apachethrift@mucker.net>:

> I'm trying to establish communications between a PHP client and a C++ server
> using the Apache thrift RPC framework. After many hours of fruitless
> debugging, I built a java server from the same thrift file and got things
> working. When I run the C++ server, none of my methods (except the
> constructor) get called, and the same client that got a response from the
> java server throws an exception Exception: TSocket: timed out reading 4
> bytes from localhost:65123 (Even though I've set both the transmit and
> receive timeouts on the client to 5 seconds.) At least this error is
> different than the error I get when the server isn't running [TSocket: Could
> not connect to localhost:65123 (Connection refused [111])], so I know the
> C++ server is at least bound to the port that the client is talking to.
>
> The (working) java server code is:
>
> public class Server
>
> {
>
>     public static void
> Start(EncabulationGame.Processor<EncabulationInputListener> processor)
>
>     {
>
>         try
>
>         {
>
>             TServerTransport serverTransport = new TServerSocket(65123);
>
>             TServer server = new TSimpleServer(new
> Args(serverTransport).processor(processor));
>
>             System.out.println("Starting the simple server...");
>
>             server.serve();
>
>         }
>
>         catch (Exception e)
>
>         {
>
>             e.printStackTrace();
>
>         }
>
>     }
>
>
>
>
>
>     public static void main(String[] args)
>
>     {
>
>         Start(new EncabulationGame.Processor<EncabulationInputListener>(new
> EncabulationInputListener()));
>
>     }
>
>
>
> }
>
> The (nonworking) C++ server is spawned in a thread separate from the main
> processing thread of my application. The code looks like:
>
> void* ListenerThreadEntryPoint(void* threadStartData)
>
> {
>
>     struct InputListenerThreadStartupData * threadData;
>
>     threadData =  ((struct InputListenerThreadStartupData *)
> threadStartData);
>
>     int port = threadData->ListnerThreadPort;
>
>
>
>     shared_ptr<EncabulationGameHandler> handler(new
> EncabulationGameHandler(threadData));
>
>     shared_ptr<TProcessor> processor(new
> EncabulationGameProcessor(handler));
>
>     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);
>
>     server.serve();
>
>
>
>     return 0;
>
> }
>
> Both the java and the C++ server code snippets are cut-and-pasted from the
> skeleton code that the thrift compiler generates.
>
> I really can't figure this out. Why is my C++ server not responding to the
> client? Why are none of the methods in my handler (other than the
> constructor) being called?
>
> Here's the code that implements my handler.
>
> class EncabulationGameHandler : virtual public EncabulationGameIf {
>
> public:
>
>   EncabulationGameHandler(InputListenerThreadStartupData * threadData) {
>
>     // Your initialization goes here
>
>   }
>
>
>
>   int32_t RegisterPlayer() {
>
>     // Your implementation goes here
>
>     printf("RegisterPlayer\n");
>
>   }
>
>
>
>   void UnRegisterPlayer(const int32_t playerID) {
>
>     // Your implementation goes here
>
>     printf("UnRegisterPlayer\n");
>
>   }
>
>
>
>   bool IsGameRunning() {
>
>     // Your implementation goes here
>
>     printf("IsGameRunning\n");
>
>   }
>
>
>
>   int32_t GetPlayerScore(const int32_t playerID) {
>
>     // Your implementation goes here
>
>     printf("GetPlayerScore\n");
>
>   }
>
>
>
>   void Bounce(const int32_t playerID) {
>
>     // Your implementation goes here
>
>     printf("Bounce\n");
>
>   }
>
>
>
>   void ChangeColor(const int32_t playerID) {
>
>     // Your implementation goes here
>
>     printf("ChangeColor\n");
>
>   }
>
>
>
> }
>
>
>
> I'm pretty sure that I'm missing something simple here, but it's been
> extraordinarily frustrating trying to solve this on my own. Any help from
> the community would be appreciated. I'm using thrift version 0.9.0.
>
>
>
> Thanks,
>
>
>
> -Matthew



Mime
View raw message