小编eya*_*vin的帖子

GET http://localhost/socket.io/?EIO=3&transport=polling&t=LjIvLGU 404(未找到)

我的 Nodejs 和我的 js 代码有问题。

当我在控制台服务器中运行 Nodejs 时没有显示任何问题,但我一直在 Chrome 控制台中收到错误消息:

GET http://localhost/socket.io/?EIO=3&transport=polling&t=LjIvLGU 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

索引.html

<head>
    <title>test</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="http://localhost:3000/socket.io/socket.io.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)

脚本.js

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

users = [];
connections = [];

server.listen(process.env.PORT || 3000);

console.log("server up");

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

io.sockets.on('connection', function (socket) {

    socket.on('subscribe', function (data) {
        socket.join(data.room);
    });
    socket.on('arriv', function (data) { …
Run Code Online (Sandbox Code Playgroud)

sockets websocket node.js express socket.io

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

node.js ×1

socket.io ×1

sockets ×1

websocket ×1