0

I've looked through the site and haven't found any guidance on connecting my QTcpSocket to my Thrift C++ server. This was the closest match, although the solutions proposed don't work.

Client code (Qt Quick Application):

QHostAddress addr {"104.236.6.118"};
quint16 port {9090};

QTcpSocket socket;
socket.connectToHost(addr, port);

if(socket.state() == QTcpSocket::ConnectedState)
{
    qDebug()<<"Connection accepted";
} else
{
    qDebug()<<"Connection failed";
} 

Server code (Thrift C++):

class testerHandler : virtual public testerIf {
   public:
     testerHandler()
     {
        printf("Got an incoming connection....");
     }    
};

int main()
{
   int port = 9090;
   shared_ptr<testerHandler> handler(new testerHandler());
   shared_ptr<TProcessor> processor(new testerProcessor(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); 

   try
   {
      server.serve();
   }
   catch (...)
   {
     printf("ERROR");
   }
   return 0;
}

Does anyone have any experience or advice on connecting these?

Community
  • 1
  • 1
Babra Cunningham
  • 2,691
  • 1
  • 17
  • 44
  • I glanced at http://stackoverflow.com/questions/20653240/what-is-rpc-framework-and-apache-thrift and it seems to me that with flexibility offered JSON interaction makes less effort and pain to implement. Sockets worth doing for achieving lower latency but with overall throughput it does not really matter which protocol to choose. But JSON is just easier. – Alexander V Mar 02 '17 at 18:25
  • Can you add a SIGNAL SLOT Connection socket connected() to slot connected() to Client Side? and you should test your client side with QTcpServer example if work you can search bug in Server side. – CMLDMR Mar 02 '17 at 18:25
  • You're assuming that if the connection state is not connected, that its failed. What is the actual state? Its possible that the connection is still in progress. – RobbieE Mar 03 '17 at 05:08

0 Answers0