Sunday, 11 June 2017

socket.io with ssl not working

I have a simple node.js code for websocket server using socket.io module and I just cannot make it work. The server runs with no errors but when trying to connect from the browser I am getting "SOCKET ERROR: {"isTrusted":true}" error (I am not using self signed certificate but Symantec certificate which is tested and is trusted by browsers).
An here is my code:

var fs = require( 'fs' ) ;
var app = require('express')();
var https  = require('https');
var server = https.createServer({    
    key: fs.readFileSync('cert.key'),
    cert: fs.readFileSync('cert.cer'),
},app);
server.listen(50100);
var io = require('socket.io').listen(server,{pingTimeout: 7000, pingInterval: 10000});
io.sockets.on('connection',function (socket) {
    console.log('new connection'); 
});

On client I am using standard java script "var WS = new WebSocket(wsUri); " and wsUri is "wss://siteaddress:50100".
I tried the code with "ws" node module and it seems to work fine but "ws" module doesnt have all the methods I need (unless I am missing something - I need to be able to send messages to selected sockets or all sockets together and send some info from client on socket connection).
I have tried all the suggestions in node.js, socket.io with SSL but none of them worked for me.

Can anybody point me in the right direction?
Thanks.



via user3195616

No comments:

Post a Comment