我对 NodeJS 真的很陌生(如果我对某些东西听起来很天真,我很抱歉)并且我一直在深入研究示例的源代码 聊天应用程序。
但是,我无法理解一件事。我知道 WebSockets 有助于处理持久的全双工双向连接。但是 NodeJS 如何在不使用 WebSockets 的情况下管理上述聊天应用程序中的持久连接呢?如果 NodeJS 可以处理持久的双向连接,那么在 Node 中集成 Socket.IO 这样的东西到底有什么作用呢?
I'm really new to NodeJS (and I'm sorry if I sound naive about some stuff) and I've been digging into the source code of the example Chat Application.
However, I'm having trouble understanding one thing. I know that WebSockets helps handle persistent full-duplex bi-directional connections. But how does NodeJS manage a persistent connection in the aforementioned chat application without the use of WebSockets? And if NodeJS can handle a persistent bi-directional connection, what exactly is the function of integrating something like Socket.IO in Node?
发布评论
评论(2)
除了 WebSocket 之外,您还可以使用长轮询技术在服务器和客户端之间创建持久连接。
然而,它不如 WebSockets 高效,但它被使用是因为它与 WebSockets 不同,可以在每个浏览器中工作。尝试看看这个文章:
Besides WebSockets you can use long polling technique to create persistent connection between server and client.
However it's not as efficient as WebSockets, but it's used because it works in every browser unlike WebSockets. Try to look at this article:
我对聊天应用程序不熟悉。我没有看到托管演示的链接。
NodeJS 是一种服务器端技术。它与本机套接字没有任何问题。 Socket.IO 是客户端和服务器端技术的结合。它只是恰好使用 NodeJS 作为服务器端。它的美妙之处在于,它在客户端提供了一个通用的通信 API,而不管浏览器实际具有什么功能。
I am not familiar with the chat application. And I don't see a link for a hosted demo.
NodeJS is a server-side technology. It has no trouble with native sockets. Socket.IO is a combination client-side and server-side technology. It just happens to use NodeJS for the server side. The beauty of it is that it presents a common communications API on the client side, regardless of what features the browser actually has.