thrift-异步client&server使用例子

本文通过一个具体的测试例子展示了如何使用Thrift实现异步客户端和服务器。包括生成Thrift文件的C++实现、定义`testClient`类、实现异步发送和接收以及服务器端的处理逻辑。最后,通过运行客户端和服务器程序验证了异步通信的正确性。
摘要由CSDN通过智能技术生成

         研究完异步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&

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值