Socket.io 400 (bad request)

I have this 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 the 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 already did it like 10 times, and I never got it. Does anyone know how to fix this?

+7
javascript ios sockets express
source share
1 answer

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

I was getting this problem when I used version 0.9.16 . I upgraded to the next and worked.

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

All Articles