1. 程式人生 > >LinuxC/C++程式設計基礎(23) 使用thrift/rpc開發簡單例項(續1)

LinuxC/C++程式設計基礎(23) 使用thrift/rpc開發簡單例項(續1)

#include <vector>
#include <boost/shared_ptr.hpp>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include "../gen-cpp/MusicServlet.h"
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using namespace shansj;
using boost::shared_ptr;
class MusicServletHandler:virtual public MusicServletIf{
public:
    MusicServletHandler(){
    }
    void sendMessage(const std::vector<Music_Info>& music){
        printf("[MusicServletHandler::sendMessage] invoke\n");
        printf("song_id:%d\n",music[0].song_id);
        printf("song_name:%s\n",music[0].song_name.c_str());
        printf("song_singer:%s\n",music[0].song_singer.c_str());
        printf("song_album:%s\n",music[0].song_album.c_str());
    }
};