Search

7/08/2013

socket.io + express.js common error

if you see this error: GET http://localhost:8000/socket.io/1/?t=1373270667022 404 (Not Found) should be server.listen(80) instead of app.listen(80)

var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('socket.io').listen(server);

server.listen(80);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

沒有留言: