Is Google Chrome supporting socket.io?
I am making a small multiplayer game using node.js and socket.io on my laptop. Occasionally, when I want to test some multiplayer features I log into the game using my PC (the PC and the laptop are connected to a LAN network). Socket.io connects to my router's IP (196. ...) and the port 8080. Everything worked well until today, and when I just wanted to see how it worked before I changed anything - suddenly it didn't. I first opened Google Chrome on my laptop and log in, that worked OK. Then, I opened Google Chrome on my PC and tried to connect, and it didn't work. First, the user enters his name and password to a form and clicks a login button, which calls this function:
login = function()
{
var n = document.forms['logn']['name'].value;
var p = document.forms['logn']['password'].value;
var socket = io.connect("http://192.168.0.13:8080");
socket.emit("login", {n: n, p: p});
socket.on("got", function(data){
开发者_开发问答 if (data.good)
{
main(socket, n)
}
else
{
alert("Failed to log in.");
}
});
}
When I the function get's called, nothing happens. I have noticed that the server logs messages similar to this:
setting request GET /socket.io/1/websocket/
But xhr-polling is more often than websocket. This is all I know for now, also, everything works OK on Firefox, so I think it's a problem with Google Chrome.
server logs when I try to log in from the PC:
debug - served static /socket.io.js debug - client authorized
info - handshake authorized 30836340583773206 debug - setting request GET /socket.io/1/websocket/30836340583773206 debug - set heartbeat interval for client 30836340583773206 debug - client authorized for debug - setting request GET /socket.io/1/xhr-polling/30836340583773206?t=1315509666877 debug - setting poll timeout debug - discarding transport debug - cleared heartbeat interval for client 30836340583773206 debug - served static /socket.io.js
I just had exactly the same issue.
I could handshake, and authenticate through Chrome but any emits were not being correctly handled on the client (although Socket.io was sending them).
Log in to your server and update socket.io.
$> npm ls
will tell you the latest version of your installed modules. In my instance I was running:
/var/www/discovery/node
├─┬ express@2.4.6
│ ├── connect@1.6.2
│ ├── mime@1.2.2
│ └── qs@0.3.1
├── iniparser@1.0.3
├── jsonrpc@0.1.1
├── jsonrpc-ws@0.0.3
├── jsonrpc2@0.0.6
├─┬ mysql@0.9.3
│ └─┬ hashish@0.0.4
│ └── traverse@0.5.1
└─┬ socket.io@0.7.9
├── policyfile@0.0.4
├── redis@0.6.6
└─┬ socket.io-client@0.7.9
├── uglify-js@1.0.6
├── websocket-client@1.0.0
└── xmlhttprequest@1.2.2
You can see that socket.io@0.7.9 is old. This also means that it doesn't have the latest ws:// websocket protocol update.
So in order to fix it, just run :
$> npm update socket.io express
精彩评论