我浏览了网站,但未找到任何有关将QTcpSocket
连接到Thrift C ++服务器的指导。 This是最接近的匹配,尽管提出的解决方案不起作用。
客户端代码(Qt快速申请):
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";
}
服务器代码(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;
}
有没有人有关于连接这些的经验或建议?