Preface: the first two articles have described thrift/RPC installation and server writing. Here we add the compiling of the Client
1. Implement the client. cpp file as follows:
# Include "../Gen-CPP/musicservlet. H"
# Include <vector>
# Include <boost/shared_ptr.hpp>
# Include <thrift/protocol/tbinaryprotocol. h>
# Include <thrift/protocol/tprotocol. h>
# Include <thrift/transport/tsocket. h>
# Include <thrift/transport/tTransport. h>
# Include <thrift/transport/tbuffertransports. h>
Using namespace: Apache: thrift;
Using namespace: Apache: thrift: Protocol;
Using namespace: Apache: thrift: Transport;
Using namespace shansj;
Using boost: shared_ptr;
Int main (INT argc, char ** argv ){
Shared_ptr <tTransport> socket (New tsocket ("localhost", 5555 ));
Shared_ptr <tTransport> transport (New tbufferedtransport (socket ));
Shared_ptr <tprotocol> protocol (New tbinaryprotocol (Transport ));
Musicservletclient client (Protocol );
Try {
Transport-> open ();
STD: vector <music_info> music;
Music_info song;
Song. song_id = 99;
Song. song_name = "qilixiang ";
Song. song_singer = "zhoujielun ";
Song. song_album = "fantexi ";
Music. push_back (Song );
Client. sendmessage (music );
Transport-> close ();
} Catch (texception & Tx ){
Printf ("error: % s \ n", TX. What ());
}
Return 0;
}
The code is concise and clear.
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8281815
II. The running result is as follows:
1. Client:
2. Server:
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8281815