gpt4 book ai didi

node.js - Socket.io websocket 错误 ENOENT

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:50 24 4
gpt4 key购买 nike

我在我的nodejs服务器上使用socket.io,它在开发环境中工作正常。但是,当我将其部署到生产服务器上时,它开始出现以下错误:

Connection Error { [Error: websocket error]
description:
{ [Error: connect ENOENT]
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'connect',
target:
{ domain: null,
_events: [Object],
_maxListeners: 10,
_socket: null,
_ultron: null,
_closeReceived: false,
bytesReceived: 0,
readyState: 0,
supports: [Object],
extensions: {},
_isServer: false,
url: 'ws://localhost:8888/socket.io/?EIO=3&transport=websocket',
protocolVersion: 13,
binaryType: 'buffer' } } }

我的服务器端代码如下:

var server = app.listen(8888);
var io = require('socket.io').listen(server);

var test_data_nsp = io.of('/test_data');
test_data_nsp.on('connection',function(socket){
console.log('Connected: %s', socket.id);
socket.on('user_connected',function(username){
console.log("user connected");
socket.on('disconnect',function(){
console.log('User Disconnected');
});
});

Mocha 中的客户端代码如下:

var io = require('socket.io-client');
var socketTestURL = 'http://localhost:8888/test_data';
var options ={
transports: ['websocket'],
'force new connection': true
};


describe("Web Socket",function(){
it('Should open a socket connection to send testdata to the user',function(done){
var client_test_data = io.connect(socketTestURL, options);
client_test_data.on('connect', function(data){
client_test_data.emit('user_connected',"test_user_name");
done();
});
})
});

我无法理解出了什么问题。任何帮助将不胜感激。

TIA:)

最佳答案

问题here .

解决方法是为 socket.io-client 添加 rejectUnauthorized: null 选项。

关于node.js - Socket.io websocket 错误 ENOENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37407977/

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