Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Is Google Chrome supporting socket.io?

Is Google Chrome supporting socket.io?

Problem

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

Problem courtesy of: jcora

Solution

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
Solution courtesy of: Layke

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Is Google Chrome supporting socket.io?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×