Socket.io websocket错误ENOENT

我在我的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 🙂

       

网上收集的解决方案 "Socket.io websocket错误ENOENT"