节俭C++服务器超时,Java 服务器不会
Thrift C++ server times out, java server doesn't
我正在尝试使用Apache thrift RPC框架在PHP客户端和c++服务器之间建立通信。经过几个小时毫无结果的调试,我从同一个节俭文件构建了一个java服务器,并使其正常工作。当我运行c++服务器时,没有调用我的任何方法,并且从java服务器获得响应的同一客户机抛出异常Exception: TSocket: timed out reading 4 bytes from localhost:65123
(即使我已将客户机上的发送和接收超时设置为5秒)。至少这个错误是不同于错误时,我得到的服务器不运行[TSocket: Could not connect to localhost:65123 (Connection refused [111])
],所以我知道c++服务器至少绑定到端口,客户端正在交谈。
(工作的)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++服务器代码片段都是从thrift编译器生成的框架代码中剪切和粘贴的。
我真的想不明白这个。为什么我的c++服务器不响应客户端?为什么我的处理程序(除了构造函数)中的方法都没有被调用?我将非常感谢社区提供的任何帮助。我使用的是thrift 0.9.0版本。下面是实现我的处理器的代码,如果它有帮助的话:class EncabulationGameHandler : virtual public EncabulationGameIf {
public:
EncabulationGameHandler(InputListenerThreadStartupData * threadData) {
// Your initialization goes here
}
int32_t RegisterPlayer() {
// Your implementation goes here
printf("RegisterPlayern");
}
void UnRegisterPlayer(const int32_t playerID) {
// Your implementation goes here
printf("UnRegisterPlayern");
}
bool IsGameRunning() {
// Your implementation goes here
printf("IsGameRunningn");
}
int32_t GetPlayerScore(const int32_t playerID) {
// Your implementation goes here
printf("GetPlayerScoren");
}
void Bounce(const int32_t playerID) {
// Your implementation goes here
printf("Bouncen");
}
void ChangeColor(const int32_t playerID) {
// Your implementation goes here
printf("ChangeColorn");
}
};
你没有给我们足够的理由继续下去-所以看看差异,自己写一个最简单的c++服务器,你可以和你的独立java服务器一样。运行c++服务器(不在线程中)
c++代码看起来很像thrift框架中的自动生成的东西,所以我看不出这有什么错。
回答我自己的问题,我设法通过使用多线程的Thrift服务器模型来解决这个问题。我从来没有弄清楚为什么上面发布的代码片段不起作用
相关文章:
- Java 客户端C++服务器数据发送/接收问题
- 无法在java(客户端)的套接字上正确写入数据(类),也无法在c ++(服务器)上读取数据(类)
- 是否可以使用InProceChannel使用Java客户端在同一过程中调用C 服务器
- 为C 服务器实施Java TCP客户端
- C 和Java,SQLite服务器同时访问
- C 客户端和Java服务器消息
- 将消息从C 服务器发送到Java客户端
- Java 服务器套接字,客户端采用 C 语言
- 如何连接客户端(在VirtualBox上)和服务器(在localhost上)?我使用CORBA和C++/Java
- C++客户端到Java服务器(TCP/IP)
- 如何在 Java 服务器和客户端之间制作 CORBA C++
- 在 Java 客户端中创建 Mat 对象,使用 opencv 从C++服务器发送
- 在 CORBA 客户端/服务器应用程序中将无符号的长整型(从 C++)断言为长整型 (Java)
- CORBA C++/Java应用程序中服务器端的分段故障(核心转储)
- 服务器应用程序的C++与Java
- C++客户端和 Java 服务器
- C++ 客户端无法与 Java 服务器通信
- c++套接字客户端在输出流关闭的情况下不断从Java服务器事件中接收一些内容
- 如何查看从服务器 Java 到C++客户端的整个消息
- 如何通过套接字C++服务器/Java客户端发送int