[英]How to detect multiple WebSocket connections from the same computer?
I have a Node.js WebSocket server and I want to prevent clients from being able to open 50 tabs which will create 50 connections. 我有一个Node.js WebSocket服务器,我想阻止客户端打开50个选项卡,这将创建50个连接。 My current idea is to check the IP addresses like this:
我当前的想法是检查IP地址,如下所示:
ws._socket.remoteAddress
and then just check that against my current connections IPs and if that IP already exists then reject the connection request. 然后根据我当前的连接IP检查该IP,如果该IP已经存在,则拒绝连接请求。 My understanding is that there will be a problem with this approach because if 2 computers are on the same Wifi and therefore have the same public IP, the second computer will be blocked.
我的理解是,这种方法会有问题,因为如果两台计算机位于同一Wifi上,因此具有相同的公用IP,则第二台计算机将被阻止。 This isn't what I want.
这不是我想要的 I want 1 connection per computer, therefore IP might not be the solution.
我想要每台计算机1个连接,因此IP可能不是解决方案。 Is this a valid problem or would my solution actually work?
这是一个有效的问题,还是我的解决方案可以实际工作? What is the best way to uniquely identify a client's computer to prevent more than 1 connection on that device?
唯一标识客户端计算机以防止该设备上的多个连接的最佳方法是什么?
Assuming you control the clients connecting, I would look at a shared web worker that is used by all tabs in that browser. 假设您控制客户端的连接,我将查看该浏览器中所有选项卡使用的共享Web worker。 This would essentially give you 1 connection for n tabs.
本质上,这将为您提供1个用于n个标签的连接。 Each browser would be a new connection though so maybe 3-4 connections at most?
每个浏览器都是一个新的连接,但最多可能只有3-4个连接?
Here is a link. 这是一个链接。 Check out the example as it spells it out pretty succinctly: https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker
请查看该示例,因为它非常简洁地说明了该示例: https : //developer.mozilla.org/zh-CN/docs/Web/API/SharedWorker
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.