简体   繁体   English

找不到Socket.io客户端错误404

[英]Socket.io Client error 404 not found

I am getting a 404 error (client side) on productive system. 我在生产系统上遇到404错误(客户端)。 If i run the server in local network, everything is fine. 如果我在局域网中运行服务器,一切都很好。

Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为404(未找到)

GET https://foo.com/socket.io/?EIO=3&transport=polling&t=MGd8e2F 404 (Not Found) GET https://foo.com/socket.io/?EIO=3&transport=polling&t=MGd8e2F 404(未找到)

I am using socket.io Version 2.1.1 and Express 4. 我正在使用socket.io 2.1.1版和Express 4。

Server.js Server.js

...
var http = require('http');
var https = require('https');
var app = express();
httpServer = http.createServer(app);
httpsServer = https.createServer(options, app);
...
const io = require('socket.io')(httpsServer);

httpServer.listen(process.env.SERVER_HTTP_PORT);
httpsServer.listen(process.env.SERVER_HTTPS_PORT);

io.use(function (socket, next) {
    //Middleware (express-session)
    e_session(socket.request, socket.request.res, next);
});
io.on('connection', function (client) {
   ...
}

client.js client.js

const socket = io('https://' + window.location.hostname + ':443');

socket.on('connect', function (data) {
  socket.emit('join', 'Server Connected to Client');
});
...

I tried also in client.js: 我也在client.js中尝试过:

const socket = io();
const socket = io('https://' + window.location.hostname);

Why can not the client connect to the server on the production system? 客户端为什么不能连接到生产系统上的服务器?

I found my mistake: The Load Balancer on the productive system sends the HTTP request to Port 80 but socket.io was listening to Port 443. I initiated socket.io with the wrong server: const io = require('socket.io')(httpsServer); 我发现了我的错误:生产系统上的负载均衡器将HTTP请求发送到端口80,但是socket.io正在侦听端口443。我使用错误的服务器启动了socket.io:const const io = require('socket.io')(httpsServer); instead of require('socket.io')(httpServer) . 而不是require('socket.io')(httpServer)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM