想整个简单的 JSON over TCP server,message framing(JSON framing)怎么设计比较好?用什么符号来作为payload之间的delimiter?怎么校验payload的完整性?

1 9hills Mar 22, 2014 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 Mar 22, 2014 其实就是包头,包长,包体。。都大同小异,没啥区别 |
3 finian OP @9hills 谢,我也Google到了那个lib,不过看他最后更新在11个月之前,而且start数比较少,所以觉得可能不是那么靠谱,我还是先看看他的代码是怎么实现的 |
4 notedit Mar 22, 2014 把json数据封装成memcache的get set |
5 rankjie Mar 22, 2014 via iPhone 非常简短的json我就是stringify了再parse lol |
6 zhujinliang Mar 22, 2014 websocket套json,协议不复杂,也有独立的C语言实现,各种语言几乎都有库。另外向上nginx能支持,可提供一些反向/权限控制等辅助,向下浏览器支持,可以方便地进行调试 |
7 9hills Mar 22, 2014 |
8 taomaree Mar 22, 2014 |
9 clino Mar 22, 2014 我自己刚好在考虑类似的问题,也想用json来做 目前的一个想法是每个json都只用一行,这样socket当作file来readline就可以取到每个json信息了 至于"怎么校验payload的完整性",只要json能load格式正确就行了,再不放心就加个校验信息好了 |