Nodejs:多个客户端通过一个套接字请求
场景:我有许多客户端(网页,通过 Socket.io)连接到 Node.js 服务器(称之为 A)。服务器充当这些客户端的另一个服务(也是 Node.js)的应用程序“代理”,我们将服务称为 B。实际上,页面使用代理与服务 B 进行通信。 我试图了解是否可以从服务器 A 到服务 B 只使用一个打开的套接字,只是为了获得性能和资源(在服务器 A 上的第一个客户端连接上,服务器将打开到 B 的套接字并维护它打开消息双向流动)。 当然,问题在于,如果没有某种干预,消息可能会被打乱,导致服务 B 无法理解的混乱。 我是套接字编程的新手,我想知道这是否是一个“已解决”的问题,或者只是问题的错误答案:) 谢谢
Scenario: I have many clients (web pages, via Socket.io) that connect to a Node.js server (call it A). The server acts as an application "proxy" to another service (Node.js too) for those clients, let's call the service B. In practice, pages talk to service B using the proxy.
I'm trying to understand if I could take ONE only open socket from the server A to the service B, just to gain performance and resources (on the first client connection on server A, the server will open the socket to B and maintain it open for message to flow bidirectionally).
Of course the problem is that without some kind of intervention, messages could be scrambled one over the other, resulting in a mess that service B can't understand.
I'm quite a newbie in socket programming, and I'm wondering if this is yet a "solved" problem, or just the wrong answer to the problem :)
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的评论来看,您似乎会受益于 Redis 的 PubSub 之类的东西。
请参阅 http://redis.io/,特别是 http://redis.io/commands#pubsub
From your comments, it looks like you'd benefit from something like Redis' PubSub.
See http://redis.io/ and specifically, http://redis.io/commands#pubsub