我正在尝试使用Apache thrift RPC框架在PHP客户机和C++服务器之间建立通信。经过几个小时的无果调试之后,我从同一个节俭文件构建了一个java服务器,并开始工作。当我运行C++服务器时,我的任何方法都不会被调用,并且从java服务器获得响应的同一客户端会抛出异常Exception: TSocket: timed out reading 4 bytes from localhost:65123
(即使我已将客户端上的传输和接收超时设置为5秒。 )至少这个错误与我在服务器没有运行时得到的错误不同[],所以我知道C++服务器至少绑定到客户端正在与之通话的端口。Thrift C++服务器超时,java服务器不支持
的(工作)的Java服务器代码是:
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()));
}
}
的(非工作)C++服务器在线程产生从我的应用程序的主处理线程分离。代码看起来像:
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;
}
Java和C++的服务器代码片段剪切并粘贴从储蓄机构编译器生成的骨架代码。
我真的不知道这一点。为什么我的C++服务器不响应客户端?为什么我的处理程序中的所有方法(构造函数除外)都被调用?我非常感谢社区可以提供的任何帮助。我正在使用节俭0.9.0构建。
下面是实现我的处理程序,如果它有助于代码:
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");
}
};