【问题标题】:socket.io-client: the server responded with a status of 404 (Not Found)socket.io-client:服务器响应状态为 404(未找到)
【发布时间】:2015-12-26 01:39:58
【问题描述】:

我正在尝试使用 npm 包 socket.io-client 使 socket.io tutorial's example 适应我的代码。

经过这次尝试,我得到了错误:

加载资源失败:服务器http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1451092774034-0响应状态为404(未找到)

下面的代码:

客户

完全按照包开发者的规定

var socket = require('socket.io-client')('http://localhost:3000');

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

服务器

var express = require('express');
var app = express();

var server = require('http').Server(app);

var io = require('socket.io')(server);

app.use(express.static(__dirname+'/app'));

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

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


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

我想问题与 app.use(express.static(__dirname+'/app')) 行有关。但是,我不知道如何利用这种怀疑来解决问题。

感谢您的帮助。

【问题讨论】:

    标签: node.js socket.io browser-sync


    【解决方案1】:

    问题解决了。相关问题与浏览器同步的一些冲突有关,如this github's issue中所述

    【讨论】:

      猜你喜欢
      • 2018-06-30
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 2023-04-10
      • 2015-12-01
      相关资源
      最近更新 更多