Dear Wiki user, You have subscribed to a wiki page or wiki category on "Thrift Wiki" for change notification.
The following page has been changed by HannesBaldursson: http://wiki.apache.org/thrift/ThriftUsageC++ ------------------------------------------------------------------------------ Make sure that your system meets the requirements as noted in ThriftRequirements == Installing the Thrift library == + Installing the Thrift library is trivial to link with the generated code. 1. Download a snapshot of Thrift and extract if you haven't done so already - [http://gitweb.thrift-rpc.org/?p=thrift.git;a=snapshot;h=HEAD;sf=tgz Direct Link] 1. Navigate to {{{lib/cpp}}} using the terminal of your choice @@ -51, +52 @@ }}} + Here's the autogenerated skeleton file to illustrate how to write a server: + '''Something_server.cpp''' + {{{ + #include "Something.h" + #include <protocol/TBinaryProtocol.h> + #include <server/TSimpleServer.h> + #include <transport/TServerSocket.h> + #include <transport/TTransportUtils.h> + using namespace facebook::thrift; + using namespace facebook::thrift::protocol; + using namespace facebook::thrift::transport; + using namespace facebook::thrift::server; + + using boost::shared_ptr; + + using namespace Test; + + class SomethingHandler : virtual public SomethingIf { + public: + SomethingHandler() { + // Your initialization goes here + } + + int32_t ping() { + // Your implementation goes here + printf("ping\n"); + } + + }; + + int main(int argc, char **argv) { + int port = 9090; + shared_ptr<SomethingHandler> handler(new SomethingHandler()); + shared_ptr<TProcessor> processor(new SomethingProcessor(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; + } + }}} +
