2
votes

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

1
Which version of Socket.IO are you using, and do they match on the client and server side? - Matt
Also, what version of Chrome is on your Mac, and what is it on the PC? I know there was a new version of the web socket protocol coming down the line - Matt
What version of Chrome are you using and what version of Socket.IO are you using? Chrome recently updated it's version of the websocket protocol in Chrome 14 (updates.html5rocks.com/2011/08/…). The good news is that the latest version of SocketIO does support this new protocol. - ebidel
Both are the same on my laptop (which is a Linux), 13.0.782.220. Socket.io is the newest version. I don't get how could they be any different on the server and the client though, server sends it to the client (I think)! - corazza
Thanks for the additional info. I'm fresh out of ideas though. If no one else on SO has anything for you, you might consider taking this to the Socket.IO google groups. The devs are fairly good about responding there. And if you do figure it out, be sure to post back here about it (as an answer to your own question) - Matt

1 Answers

5
votes

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
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
│   └── [email protected] 
└─┬ [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  └─┬ [email protected] 
    ├── [email protected] 
    ├── [email protected] 
    └── [email protected] 

You can see that [email protected] 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