Build a whole site using just websockets (via socket.io and node.js, no Ajax)?

前端 未结 4 1612
囚心锁ツ
囚心锁ツ 2021-02-08 07:39

Is this possible? Has anyone tried it?

Using websockets means there are no httpheaders being exchanged (like in a Ajax request) so there is definately a boost in speed o

4条回答
  •  深忆病人
    2021-02-08 07:45

    It is definitely possible but I have not tried it. You will get a latency boost but the bandwidth boost will not be significant. The real problem is not going to be server resources (continuously polling the server via AJAX is likely harder on the server in most ways), but that AJAX has really solved a lot of the problems (especially the ones you will run into as your scope increases) so you will be rebuilding a lot of stuff for custom use.

    Unless you are actually running into a latency problem, I would suggest using standard AJAX. Or only use WebSockets for the part of you application that actually needs low latency so you are not recreating all the wheels.

    Yes, being able to have multiple clients connect to one listening port simultaneously is possible and done all the time (your web server almost certainly does so on port 80 for example). Your WebSocket server will have to handle the incoming connections properly (evented, threaded, or multi-process) but it's pretty much standard fair (google "socket programming YOUR_LANGUAGE").

提交回复
热议问题