欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

高性能TcpServer - 1.网络通信协议

程序员文章站 2022-08-08 19:46:42
高性能TcpServer - 1.网络通信协议 高性能TcpServer - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP) 高性能TcpServer - 3.命令通道(处理:掉包,粘包,垃圾包) 高性能TcpServer - 4.文件通道(处理:文件分包 ......

高性能tcpserver - 1.网络通信协议

高性能tcpserver - 2.创建高性能socket服务器socketasynceventargs的实现(iocp)

高性能tcpserver - 3.命令通道(处理:掉包,粘包,垃圾包)

高性能tcpserver - 4.文件通道(处理:文件分包,支持断点续传)

高性能tcpserver - 5.客户端管理

高性能tcpserver - 6.代码下载

协议规范

通信采用gb2312编码格式

 

数据包格式:

标示符=长度#设备编号#任务id#包类型#包内容#

备注:长度: 4位不足补0,从标示符#到#之间的长度大小

 

数据包范例

1. 包内容为空

htemp=0026#1533022506#meter-001#01##

2. 包内容含有多个字段

htemp=0043#1533022506#meter-001#01#get-version@nb001#

3. 包内容含有多个字段(字段间用@分割,字段内的数组用[{},{}])

htemp=0261#watermeter-001#1520557005#03#buildid=44@edmid=37@meter=1228@denddate=2018-02-05 17:36:22@[{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}]#

 

协议内容

 

.心跳包 (包类型: 01)

htemp=0026#meter-001#1533022506#01##

htemp=0028#meter-001#1533022506#01#ok#

.时间同步 (包类型: 02)

htemp=0026#meter-001#1533022506#02##

htemp=0045#meter-001#1533022506#02#2018-08-16 09:50:58#

.数据上传 (包类型: 03)

htemp=0256#meter-001#1520557005#03#buildid=44@edmid=37@meter=1228@denddate=2018-02-05 17:36:22@[{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}+{132,0.0000}]#

htemp=0048#meter-001#1520557005#03#error@服务器返回失败!#

htemp=0028#meter-001#1520557005#03#ok#

.版本查询 (包类型: 04)输入:软件类型(nb001) 输出:版本号

htemp=0044#meter-0001#1533022507#04#get-version@nb001#

htemp=0028#meter-0001#1533022507#04#2#

.软件更新 (包类型: 05)输入:软件类型(nb001) 输出:包数

htemp=0042#meter-0001#1533022508#05#get-count@nb001#

htemp=0029#meter-0001#1533022508#05#16#

.软件下载 (包类型: 06)输入:包索引 输出:包数据

htemp=0044#meter-0001#1533022508#06#do-update@nb001@1#

htemp=0495#meter-0001#1533022508#06#504b03041400000008007a640f4d6bebfdba000e00004d2e000007000000636f6d732e7079d51a6b73d356f6bb7fc55d7932926ac7d80ea1901db10d8901cf244ed636fb189af1c8d275a246b6bc924c603b9d816e29852dd09d6e976d0b944e4bb7b3db02edd22729fd3328099ff80b7bee4b962c3ba4e36dbbab99c4d23dcf7bceb9f79c7ba4349a7c6612198e6975566750cf6f350e929194d5ee3aae8fbc339eb8b59dd55540128fbed5c6e2beed98cd9ed7f0d713033913b7ac0ef690ee21c3f393707647c0ec6e1446c3f57b7d2cf23412d337ba114c780a27835d4bb7c553cfb56dab59ccb2df#

.版本更新 (包类型: 07)输入:edmid@version 输出:结果

htemp=0046#meter-0001#1533022509#07#update-version@56@2#

htemp=0029#meter-0001#1533022509#07#ok#