1
9hills 2014-03-22 10:13:35 +08:00 1
Google 到有现成的 https://www.npmjs.org/package/json-over-tcp
Protocol If you would like to implement the protocol yourself, the server will expect the following in order in the byte stream: 16-bit unsigned little-endian integer with 206 as the value. This is the protocol signature, if a message is sent without this signature a protocol error will be raised. A 32-bit unsigned little-endian integer with the length of the message being sent as the value. A UTF-8 string with the stringified JSON as the value (the message). 校验没必要,TCP保证通信完整性,自带校验 更低层才要校验,比如以前设计的串口通信协议,这种不可靠环境才需要自己做校验 |
2
9hills 2014-03-22 10:14:27 +08:00
其实就是包头,包长,包体。。都大同小异,没啥区别
|
3
finian OP @9hills 谢,我也Google到了那个lib,不过看他最后更新在11个月之前,而且start数比较少,所以觉得可能不是那么靠谱,我还是先看看他的代码是怎么实现的
|
4
notedit 2014-03-22 10:43:04 +08:00
把json数据封装成memcache的get set
|
5
rankjie 2014-03-22 11:03:15 +08:00 via iPhone
非常简短的json我就是stringify了再parse
lol |
6
zhujinliang 2014-03-22 11:31:26 +08:00
websocket套json,协议不复杂,也有独立的C语言实现,各种语言几乎都有库。另外向上nginx能支持,可提供一些反向/权限控制等辅助,向下浏览器支持,可以方便地进行调试
|
7
9hills 2014-03-22 11:45:40 +08:00 1
|
8
taomaree 2014-03-22 16:39:22 +08:00
|
9
clino 2014-03-22 20:50:22 +08:00
我自己刚好在考虑类似的问题,也想用json来做
目前的一个想法是每个json都只用一行,这样socket当作file来readline就可以取到每个json信息了 至于"怎么校验payload的完整性",只要json能load格式正确就行了,再不放心就加个校验信息好了 |