HTTP vs Websockets with respect to overhead

点点圈 提交于 2019-11-30 13:31:51

If you intend to use node.js for both client and server then you should use native net module with pure sockets rather than WebSockets. Pure sockets are much better optimized for data transfer, especially binary. As far as I know browser WebSockets do not even support binary transfer yet.

I was searching around for something else and I found this post that explains websockets pretty well:

http://blog.new-bamboo.co.uk/2009/12/7/real-time-online-activity-monitor-example-with-node-js-and-websocket

Here are some pretty interesting parts from the article:

Websocket enables you to have continuos communication in significantly less network overhead compared to existing solution.

And:

During making connection with WebSocket, client and server exchange data per frame which is 2 bytes each, compared to 8 kilo bytes of http header when you do continuous polling.

For my use case (no browser), this seems like the optimal solution! Now I just need to decide whether I want to have a single websocket or multiple websockets per client (I'm leaning towards a single one at this point).

I really hope this is useful to someone. I'll leave this open for the time being. I'll be attending a JS conference later this week, and if I learn anything more I'll add to this post.

For those of you who care about browser support, see this. It looks like WebKit is the only reliable engine that supports it (Chrome and Safari).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!