研究完异步client&server源码后,当然需要写个测试例子来验证一下!
同样采用test.thrift作为例子
/* @file : test.thrift */
namespace cpp thrift.example
service Twitter {
string sendString(1:string data);
}
输入如下命令,自动生成实现异步client&server所需的类:
thrift -r -strict --gen cpp:cob_style -o ./ test.thrift
用户只要关心TwitterCobClient、TwitterCobSvIf和TwitterAsyncProcessor这三个类。
一、实现异步client
/*@file: testclient.cpp*/
#include <stdio.h>
#include <getopt.h>
#include <event.h>
#include <string>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <protocol/TBinaryProtocol.h>
#include <transport/TSocket.h>
#include <transport/TTransportUtils.h>
#include <async/TEvhttpClientChannel.h>
#include "Twitter.h&