socket.io: Clients don't receive messages
I have server and clients in node.js.
Every time client connects to server:
var response = {};
if (currentPlayers < maxPlayers) {
currentPlayers++;
response.username = currentPlayers;
players[currentPlayers] = {
score: 0
};
socket.join('players');
} else {
if (currentPlayers === maxPlayers) {
//Set a little delay
setTimeout(function () {
//I also tried this:
//players_sockets.forEach(function (s) {
// s.emit('start');
//});
io.to('players').emit('start');
}, 1500);
}
}
Server checks is there enough players for game, if it is, server emits start message. The problem is that some clients doesn’t receive this message(to be current: mobile devices(e.g. meizu mx5, iphone 5, iphone 5s and some others).
I watched debug: they are using long-polling.
Desktop clients, which are connected with WebSocket are okay.
How i need to fix this? Or maybe I’m doing something wrong?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (1 by maintainers)
Socket.io doesn’t replace long polling. And by design it can fallback to XHR long polling if web sockets are unavailable or socket.io isn’t too warm and fuzzy about the web socket implementation. For whatever reason some browsers/clients make it switch to the fallback. I worked on an application where I only wanted web sockets. So I enforced it via the connection configuration using `“transports” : [“websocket”]`` and used Modenizr to ensure web sockets were available. This did the trick for me and the browsers quit performing a fallback to XHR long polling.