socket类型:websocket 心跳包:# (直接发送一个#号 心跳超时时间:60秒) 端口号 2022

协议数据基础结构

    {"action":"XX"}

协议采用json格式,为了书写方便,后面的内容只提供参数说明,请自行转换成json数据

客户端协议 (客户端向服务器发送数据)

设置用户名(当用户第一次进入需要设置用户名,没有设置用户名将无法进行游戏) action=setname data=用户名 准备游戏 action=prepare 认输 action=surrender 发消息 action=sendmsg msg=消息内容 落子 x,y表示棋子坐标(0,0)为左上角坐标,type 棋子类型(1白/2黑) action=down x=1 y=1 type=1 进入房间 action=join 申请获取用户列表 action=userlist 申请获取服务器版本 action=version

服务端协议 (服务器向客户端发送数据)

进入房间 当前棋子类型(1白子 2黑子) 开始游戏

 action=join board=1 data=用户名

下子 action=down x=2 y=5 和棋 action=adraw 认输(白棋) action=surrender board=1 出错 msg表示错误类型 action=error msg= 发送信息 msg表示信息内容 action=sendmsg msg= 清空棋盘 action=clearboard 棋盘数据 收到和棋时,双方取消准备 action=board 用户离开 缺少关键位置(暂未实现) action=missing 游戏结束 action=end 更新棋盘状态 0准备中 1白子阶段 2黑子阶段 3结束 action=state state=0 发送用户列表

{"action":"userlist","msg":"","data":[{"name":"用户1","login_time":1627274517}]}

发送服务器版本 action=version data=版本号

发表评论

邮箱地址不会被公开。 必填项已用*标注