Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Thrift Wiki" for change 
notification.

The "ThriftUsageC++" page has been changed by dianfan.
http://wiki.apache.org/thrift/ThriftUsageC%2B%2B?action=diff&rev1=28&rev2=29

--------------------------------------------------

        $(RM) *.o something_server something_client
  }}}
  
+ == Appendix: About TNonblockingServer ==
+ If you are writing an application that will serve a lot of connection (like 
php front end calling thrift service), you'd better use TNonblockingServer. 
TNonblockingServer can accept a lot of connections while throttling the 
processor threads using a pool.
+ 
+ * TNonblockingServer with a thread pool is the c++ alternative of the JAVA 
THsHaServer;
+ * TNonblockingServer withOUT a thread pool is the c++ alternative of the JAVA 
TNonblockingServer;
+ 
+ Server code with thread pool:
+ {{{
+     shared_ptr<TProcessor> processor(new SomethingProcessor(handler));
+     shared_ptr<TProtocolFactory> protocolFactory(new 
TBinaryProtocolFactory());
+ 
+     // using thread pool with maximum 15 threads to handle incoming requests
+     shared_ptr<ThreadManager> threadManager = 
ThreadManager::newSimpleThreadManager(15);
+     shared_ptr<PosixThreadFactory> threadFactory = 
shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
+     threadManager->threadFactory(threadFactory);
+     threadManager->start();
+     TNonblockingServer server(processor, protocolFactory, port, 
threadManager);
+     server.serve();
+ 
+     // ...
+ }}}
+ 
+ C++ client code (you have to use TFramedTransport here):
+ {{{
+     boost::shared_ptr<TSocket> socket(new TSocket("localhost", 8888));
+     boost::shared_ptr<TTransport> transport(new TFramedTransport(socket));
+     boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+ 
+     SomethingClient client(protocol);
+     transport->open();
+     // do something here...
+     transport->close();
+ }}}
+ 
+ PHP client code (you have to use TFramedTransport here):
+ {{{
+     $transport = new TFramedTransport(new TSocket("localhost", 8888));
+     $transport->open();
+     $protocol = new TBinaryProtocol($transport);
+     $client= new SomethingClient($protocol, $protocol);
+     // do something here...
+     transport->close();
+ }}}
+ 

Reply via email to