linux学习记录(thrift-习题课) 10.13
游戏端game : match_client
匹配系统端match_system : match_server、save_client
数据存储端 :save_server(不需要实现)
评测方式:
注意:每次评测前重启server,且不能同时运行两个server(原因是server监听9090端口)
(1)开个tmux,分左右,左边进服务器cd /match_system/src 运行./main 右边homework test 6
(2)开两个acterminal,一个运行server,一个测试
结构:
(1)cd homework/lesson_6/thrift_lesson/thrift
发现两个接口,match.thrift 用于连接 game端的match_client 和 match_system端的match_server,save.thrift 用于连接 match_system端save_client 和 数据存储端
(2)cd homework/lesson_6/thrift_lesson/game/src
需要这里实现match_client逻辑:match_client
(3)cd homework/lesson_6/thrift_lesson/match_system/src
需要在这里实现match_server逻辑:match_server、save_client
match_system端
match_system/src下
(1)match_server的生成
thrift -r --gen cpp ../../thrift/match.thrift
改名:mv gen-cpp match_server
cd match_server
rm Match_server.skeleton.cpp
(2)save_client的生成
thrift -r --gen cpp ../../thrift/save.thrift
改名:mv gen-cpp save_client
cd save_clicent
rm Save_server.skeleton.cpp
(3)main.cpp主逻辑
vim main.cpp
复现main.cpp
match_system/src/main.cpp · master · tiankaiwen / thrift_lesson · GitLab (acwing.com)
编译:
g++ -c main.cpp match_server/*.cpp save_client/*.cpp (.cpp变.o)
编译器会自动通过.cpp里include的头文件找到对应的.h头文件,所以.h文件不管
链接:
g++ *.o -o main -lthrift -pthread
将所有的.o文件链接在一起,生成可执行文件
-lthrift,指在编译的时候,将所有thrift的预编译好的动态链接文件直接链接进来
-pthread,用到多线程
注:每次修改了哪个.cpp,才需要重新编译链接
game端:
game/src下
(1)match_client的生成
thrift -r --gen py ../../thrift/match.thrift
改名:mv gen-py match_client
cd match_client/match
rm Match-remote
(2)client.py的生成
vim client.py
复现client.py
game/src/client.py · master · tiankaiwen / thrift_lesson · GitLab (acwing.com)
python3 client.py运行
注:想试试其他端口,main.cpp和client.py都要改

浙公网安备 33010602011771号