Basic socket.io application not working-Collection of common programming errors
I created and ran a nodejs
file server.js
:
var io = require('socket.io').listen(8080);
io.set('log level', 1);
io.sockets.on('connection', function (socket) {
// pass
});
and a client client.js
:
window.onload = function(){
var connected = function(){
console.log("connect")
}
var start = function() {
socket = new io.Socket();
socket.connect('http://localhost:8080');
socket.on('connect', connected);
};
start();
}
I included socket.io
:
but in the debugger I look: Request URL:http: //undefined/socket.io/1/?t=1359905123022
I’m using django, and I ran django server in 8000 port…
WTF?
-
try to replace this lines in client.js:
socket = new io.Socket(); socket.connect('http://localhost:8080');
to:
var socket = io.connect('http://localhost:8080');
Originally posted 2013-11-09 19:42:53.