0
点赞
收藏
分享

微信扫一扫

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)

第一天: 实现匹配的客户端(game)和服务端(match_system)

thrift官方文档 

​​Apache Thrift - Homehttps://thrift.apache.org/​​

我的Git仓库

注意:不会事无巨细,只是记录一下大致的流程,感悟

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环境] 基于thrift模拟游戏的简易匹配机制(一)_thrift

例如:Match_server.skeleton.cpp

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_c++_02

 把gen-cpp改名为match_server(因为我们还要实现save_data的client端)

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_c++_03

把Match_server.skeleton.cpp重命名为main.cpp,移到src文件夹下

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_linux_04

先添加返回值(先编译通过再逐步添加)

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_python_05

 记得修改头文件的路径[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_linux_06

编译,链接(需要用到thrift的动态链接库,加上-lthrift)

g++ -c main.cpp 
g++ *.o -o main -lthrift

同理完成game部分(Python),具体代码参见git...

接下来先运行服务端,(我们在main.cpp加入了简单的输出,为了在这里能够直观看出效果)

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_linux_07

 然后运行客户端(即游戏), 可见服务端立刻有了"add_user"的响应,每执行一次都会有对应的响应, perfect!

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_linux_08

git提交一下

总结:

今天主要实现结构如下, 实现了客户端添加玩家时(add user)服务端进项响应, 主要收获是体会到了thrift在跨语言开发上的便捷

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_c++_09

[linux环境] 基于thrift模拟游戏的简易匹配机制(一)_linux_10


举报

相关推荐

0 条评论