gpt4 book ai didi

node.js - Socket IO 连接到 ws ://someAddress was interrupted while the page was loading

转载 作者:搜寻专家 更新时间:2023-11-01 00:08:11 25 4
gpt4 key购买 nike

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

// INDEX.JS Filevar 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 connection to ws://localhost:3000/socket.io/?EIO=2&transport=websocket&sid=i0SyiRvHJC1GUiafAAAC was interrupted while the page was loading.

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

最佳答案

完全以您的示例为准,对我来说效果很好。我确实收到一个错误,但与您指示的不一样(这很好,因为这里不存在此 session ):

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

index.html 是否在正确的路径中(您的应用可见)?

关于node.js - Socket IO 连接到 ws ://someAddress was interrupted while the page was loading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24315692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com