解决方法
这取决于浏览器.
看到:
> HTTP simultaneous connections per host limit… are per tab,browser instance or global?
> HTML5 websockets: max number of open connections?
似乎可能的开放Websocket的最大数量是由浏览器实现定义的,并且很难找到数字.
在Chromium源代码(Google Chrome for Linux)中,每个主机最多可以看到30个,总共256个.
// Limit of sockets of each socket pool. int g_max_sockets_per_pool[] = { 256,// NORMAL_SOCKET_POOL 256 // WEBSOCKET_SOCKET_POOL }; // Default to allow up to 6 connections per host. Experiment and tuning may // try other values (greater than 0). Too large may cause many problems,such // as home routers blocking the connections!?!? See http://crbug.com/12066. // // WebSocket connections are long-lived,and should be treated differently // than normal other connections. 6 connections per group sounded too small // for such use,thus we use a larger limit which was determined somewhat // arbitrarily. // TODO(yutak): Look at the usage and determine the right value after // WebSocket protocol stack starts to work. int g_max_sockets_per_group[] = { 6,// NORMAL_SOCKET_POOL 30 // WEBSOCKET_SOCKET_POOL };
在Firefox配置中,(转到about:config并搜索network.websocket)我可以看到每个主机最多有6个持久连接,总共200个,但显然是持久性连接限制does not affect WebSocket connections,所以只有200个限制适用.
关于方法……
我的建议是每页/每页应使用一个.如果您将小部件作为框架,请使用.postMessage(+info)在框架和主页面之间进行通信,并让主页面通过单个连接与服务器进行通信.使用发布者/订阅者模型允许不同的小部件订阅特定事件.
拥有如此多的连接会浪费浏览器和服务器上的资源.