Markuz Shultz
Markuz Shultz

Reputation: 678

Socket.io 400 (Bad Request)

I have this piece of code on my server

    var express = require('express');
    var routes = require('./routes');
    var user = require('./routes/user');
    var http = require('http');
    var path = require('path');

var app = express();
    var server = require('http').Server(app);
    var io = require('socket.io')(server);

    server.listen(3000);

    io.sockets.on('connection', function (socket) {
      console.log("Socket connected");
    });

I just want to create a connection

and on the client -

<script src="public/javascripts/socket.io.js"></script>
     <script>
        var socket = io.connect('http://127.0.0.1:3000');
     </script>

And when I open my browser I get this error in console:

GET http://127.0.0.1:3000/socket.io/1/?t=1404410309733 400 (Bad Request) socket.io.js:1659
XHR finished loading: GET "http://127.0.0.1:3000/socket.io/1/?t=1404410309733". 

I've already done this like 10 times and I never get this. Does anyone know how to fix it?

Upvotes: 9

Views: 21611

Answers (1)

Mritunjay
Mritunjay

Reputation: 25882

I think an older version of socket-io could be the reason.

I was getting this problem when I was using 0.9.16 version. I upgraded to following and it worked.

<script src="https://cdn.socket.io/socket.io-1.0.6.js"></script>

Upvotes: 13

Related Questions