仅使用 websockets(通过 socket.io 和 node.js,没有 Ajax)构建整个站点? [英] Build a whole site using just websockets (via socket.io and node.js, no Ajax)?

查看:21
本文介绍了仅使用 websockets(通过 socket.io 和 node.js,没有 Ajax)构建整个站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?有人试过吗?

Is this possible? Has anyone tried it?

使用 websockets 意味着没有 httpheaders 被交换(就像在 Ajax 请求中一样)所以肯定会提高页面显示的速度,但是有了套接字,即使什么也没有发生,你也保持与服务器的连接,是随着用户数量的增加,这是否有害?

Using websockets means there are no httpheaders being exchanged (like in a Ajax request) so there is definately a boost in speed of page display, however with the sockets you are holding a connection to the server even when nothing maybe happening, is this detrimental as number of users increase?

在客户端和服务器之间保持连接的情况下,服务器还可以处理在同一端口上连接的其他客户端吗?

with a connection being held between client and server, can the server still handle other clients connecting on the same port?

推荐答案

这绝对是可能的,但我还没有尝试过.您将获得延迟提升,但带宽提升不会显着.真正的问题不是服务器资源(在大多数情况下,通过 AJAX 持续轮询服务器在服务器上可能更难),但 AJAX 确实解决了很多问题(尤其是那些你会遇到的问题)增加),因此您将重建大量用于自定义使用的东西.

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.

除非您确实遇到延迟问题,否则我建议使用标准 AJAX.或者仅将 WebSockets 用于实际需要低延迟的应用程序部分,这样您就不会重新创建所有轮子.

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.

是的,能够让多个客户端同时连接到一个侦听端口是可能的,并且一直都在完成(例如,您的 Web 服务器几乎肯定会在端口 80 上这样做).您的 WebSocket 服务器必须正确处理传入的连接(事件、线程或多进程),但这几乎是标准的公平(谷歌套接字编程 YOUR_LANGUAGE").

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").

这篇关于仅使用 websockets(通过 socket.io 和 node.js,没有 Ajax)构建整个站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆