Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  163] [ 1]  / answers: 1 / hits: 21359  / 10 Years ago, thu, july 3, 2014, 12:00:00

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?


More From » ios

 Answers
37

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>

[#70328] Tuesday, July 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
warren

Total Points: 679
Total Questions: 115
Total Answers: 78

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;