高性能TcpServer(C#) - 1.网络通信协议

高性能TcpServer(C#) - 1.网络通信协议

高性能TcpServer(C#) - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP)

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

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

高性能TcpServer(C#) - 5.客户端管理

高性能TcpServer(C#) - 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#

 

posted @ 2019-07-24 16:03  CHHC  阅读(4138)  评论(0编辑  收藏  举报