I am using socket.io on my nodejs server, and it is working fine in dev environment. However, when I deployed it on production server, it started giving the following error:
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' } } }
My server side code is the following:
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');
});
});
And client Side code in Mocha is the following:
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();
});
})
});
I cannot understand what went wrong. Any help will be highly appreciated.
TIA :)
Issue here .
Workaround is to add rejectUnauthorized: null
option for socket.io-client
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.