TSimpleServer
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<TimeServiceHandler> handler(new TimeServiceHandler());
shared_ptr<TProcessor> processor(new TimeServiceProcessor(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,threadManager);
server.serve();
return 0;
}
TThreadPoolServer
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<TimeServiceHandler> handler(new TimeServiceHandler());
shared_ptr<TProcessor> processor(new TimeServiceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(10);
shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
cout << "thread Start Ok !!!" <<endl;
TThreadPoolServer server(processor, serverTransport, transportFactory, protocolFactory,threadManager);
server.serve();
return 0;
}
TThreadServer
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<TimeServiceHandler> handler(new TimeServiceHandler());
shared_ptr<TProcessor> processor(new TimeServiceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<PosixThreadFactory> threadFactory(new PosixThreadFactory());
TThreadedServer server(processor, serverTransport, transportFactory, protocolFactory,threadFactory);
server.serve();
return 0;
}