You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by Apache Wiki <wi...@apache.org> on 2010/02/22 12:15:55 UTC

[Thrift Wiki] Update of "ThriftUsageC++" by DaleJohnson

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 DaleJohnson.
http://wiki.apache.org/thrift/ThriftUsageC%2B%2B?action=diff&rev1=13&rev2=14

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

  ld -L/usr/local/lib -lthrift *.o -o Something_server
  }}}
  
+ 
+ === Exploring the generated code - A Client ===
+ 
+ A client is a bit simpler to generate.
+ 
+ {{{
+ #include "gen-cpp/DocRetrieval.h"  // As an example
+ 
+ #include <transport/TSocket.h>
+ #include <transport/TBufferTransports.h>
+ #include <protocol/TBinaryProtocol.h>
+ 
+ #include <boost/unordered_map.hpp>
+ #include <boost/foreach.hpp>
+ #include <boost/lexical_cast.hpp>
+ 
+ #include <hadoop/StringUtils.hh>
+ 
+ using namespace apache::thrift;
+ using namespace apache::thrift::protocol;
+ using namespace apache::thrift::transport;
+ 
+ 
+ int main(int argc, char **argv) {
+   boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
+   boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
+   boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+ 
+   DocRetrievalClient client(protocol);
+   transport->open();
+   DocInstance doc;
+   if (argc == 2)
+     client.get(doc, atoi(argv[1]));
+   transport->close();
+ 
+   return 0;
+ }
+ 
+ }}}
+