提问者:小点点

套接字IO加载页时,与%ws://someAddress的连接中断


我试图跟随一个位于http://socket.io/get-started/chat/的socket.io的简单示例。到目前为止,我的index.js文件中有以下代码:

// 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');
});

我得到的错误是:

加载页面时,与ws:/localhost:3000/socket.io/?eio=2&transport=websocket&sid=i0syirvhjc1guiafaaac的连接中断。

我正在使用Firefox浏览页面。它在chrome中也不起作用。


共1个答案

匿名用户

拿你的例子对我很管用。我确实得到了一个错误,但与您所指示的不同(这很好,因为此处不存在该会话):

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

index.html的路径是否正确(应用程序可见)?