3

I am trying to follow along with a simple example of Socket.IO located at http://socket.io/get-started/chat/. So far I have the following code in my index.js file:

// INDEX.JS File

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

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

io.on('connection', function (socket) {
    socket.on('chat message', function (msg) {
        console.log('message: ' + msg);
    });
});
http.listen(3000, function () {
    console.log('listening on *:3000');
});

The error I am getting is:

The connection to ws://localhost:3000/socket.io/?EIO=2&transport=websocket&sid=i0SyiRvHJC1GUiafAAAC was interrupted while the page was loading.

I'm using FireFox to browse the page. It also doesn't work in Chrome.

Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
jetstreamin
  • 407
  • 5
  • 19
  • this is quite similar to this issue [socket.io 404 not found] (https://stackoverflow.com/questions/48198835/socket-io-404-error/48255983#48255983) – Marlon Buendia Jan 15 '18 at 02:27

1 Answers1

0

Taking exactly your example works fine for me. I do get an error but not the same you are indicating (which is fine since this session does not exist here):

{
  code: 1,
  message: "Session ID unknown"
}

Is the index.html in the right path (visible by your app)?

Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
Stefan
  • 1,214
  • 1
  • 9
  • 17
  • Yes. They are both in the same folder. I cloned the project and it works now. I am not sure why I am getting that error message but it doesn't seem to effect the application. – jetstreamin Jun 19 '14 at 21:31
  • 1
    Strange indeed. In any case I am glad it works now. If you need any other help, just drop a line. – Stefan Jun 20 '14 at 07:41