Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制
thrift官方文档
Apache Thrift - Homehttps://thrift.apache.org/
我的Git仓库
文件 · master · Knight bit / thrift_lesson · GitLab (acwing.com)
文章图片
https://git.acwing.com/knight/thrift_lesson/-/tree/master
注意:不会事无巨细,只是记录一下大致的流程,感悟
目录
第一天: 实现匹配的客户端(game)和服务端(match_system)
总结:
第一天: 实现匹配的客户端(game)和服务端(match_system)
thrift_lesson/thift/match.thrift
创建两个接口 添加用户add_user和删除用户remove_user
i32 add_user(1: User user, 2: string info), i32 remove_user(1: User user, 2: string info),
实现match_system服务端
thrift_lesson/match_system/src文件夹下
thrift -r --gen cpp ../../thrift/match.thrift
由此自动生成了一些接口相关的代码,非常nice, 真正需要我们实现的是具体业务
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/cadaaa28fccf486cac01551a9944e073.jpg)
文章图片
例如:Match_server.skeleton.cpp
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/04385f6e95ca496abe60c7968c6a89f8.jpg)
文章图片
把gen-cpp改名为match_server(因为我们还要实现save_data的client端)
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/bd77e54037224da0bbc7694efe552438.jpg)
文章图片
把Match_server.skeleton.cpp重命名为main.cpp,移到src文件夹下
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/b6a8eb4d7f5c4c6794ed34cc024aace1.jpg)
文章图片
先添加返回值(先编译通过再逐步添加)
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/224cf1e6f20d442f8eb0dd742e63d57d.jpg)
文章图片
记得修改头文件的路径
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/aba99a7e3557497baf98060c118bc545.jpg)
文章图片
编译,链接(需要用到thrift的动态链接库,加上-lthrift)
g++ -c main.cpp
g++ *.o -o main -lthrift
同理完成game部分(Python),具体代码参见git...
接下来先运行服务端,(我们在main.cpp加入了简单的输出,为了在这里能够直观看出效果)
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/ca1bfb1ff8ab44ea9867f9daa98e9e78.jpg)
文章图片
然后运行客户端(即游戏), 可见服务端立刻有了"add_user"的响应,每执行一次都会有对应的响应, perfect!
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/96c32ee54e92459f99897d31b9a2a6a0.jpg)
文章图片
git提交一下
总结: 今天主要实现结构如下, 实现了客户端添加玩家时(add user)服务端进项响应, 主要收获是体会到了thrift在跨语言开发上的便捷
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/1e9249c96e9440e29aa7966de8515992.jpg)
文章图片
![Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制](https://img.it610.com/image/info8/eb1fb1dd8ba74432b79d98455a87925d.jpg)
文章图片
【Linux|[linux环境] 基于thrift模拟游戏的简易匹配机制】
推荐阅读
- 人生感悟记#环境仪器宋庆国成长记#072
- 六步搭建ES6语法环境
- Linux下面如何查看tomcat已经使用多少线程
- Beego打包部署到Linux
- Linux|109 个实用 shell 脚本
- linux定时任务contab
- 芯灵思SinlinxA33开发板Linux内核定时器编程
- iOS,打Framework静态库
- day16-Linux|day16-Linux 软件管理
- win10环境|win10环境 python3.6安装pycrypto-2.6.1的问题