我正在使用Apache Thrift来设置c ++服务器。在服务器端,我想执行
execl("a.out","",(char *)NULL);
但要么首先执行上面的代码行,要么首先执行server.serve()。有没有办法让服务器启动并让代码行在服务器上运行?
我尝试将它放在message_test函数中,但我只希望它在每次启动客户端时都执行一次。
a.cpp:
int main(){
cout<<"I have started up"<<endl;
string message;
while (cin >> message){
cout<<"your message is: "<<message<<endl;
}
cout<<"I have now exited"<<endl;
}
Server.cpp
class ThforkServiceHandler : virtual public ThforkServiceIf {
public:
ThforkServiceHandler() {
// Your initialization goes here
}
void message_test(const std::string& message) {
// Your implementation goes here
printf("message_test\n");
}
};
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<ThforkServiceHandler> handler(new ThforkServiceHandler());
shared_ptr<TProcessor> processor(new ThforkServiceProcessor(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;
}