Reputation: 33
I am using socket.io with xhr polling on my chat system.I don't want to use websocket because not working on all users.But when I use xhr polling if user open 5 tabs on the browser,messages slowing down.
Same problem here
https://github.com/LearnBoost/socket.io/issues/1145
I tested it but not worked.Still have 5 connections limit.How can I disable this limit ?
Upvotes: 2
Views: 755
Reputation: 3354
I come across this question quite late, but it seems that you have reached the connection limit of your browser. By default, the browser has a limit on how many connection to a host:port can be opened at one time (Chrome allows 8 for example)
So, for your socket.io case, when you open 5 tabs to the same domain which means that you have used 5 connections allowed by your browser. For normal websites, it is not a problem because you request and receive a response, then the connection is closed. But for socket.io (and related libraries), the connection is kept opened at all time to receive "server-push" data. I might be wrong, but at least this is the problem with my project (I don't use Socket.IO but a similar library)
The solution is to limit the number of socket.io connections in your application so that there will be only 1 connection at all time. The rest of the communication should be done via cross-tab (cross-window) events (through LocalStorage for example). The result is that you have 1 tab (window) holds the real socket.io connection and broadcasts events (received from socket.io) to the other tabs (windows). Of course, there are many other factors that you need to consider when you actually implement it
P/s: I am sorry for my bad English
Upvotes: 1
Reputation: 249153
You provided the solution yourself--the bug ticket you linked has links to a solution at the end, which is basically to add this:
var http = require('http');
http.globalAgent.maxSockets = 100;
http.Agent.maxSockets = 100;
Or whatever maximum value you want.
Upvotes: 0