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.
Tried debugging by DEBUG=* node myapp - here what I get in the log:
express:application set "x-powered-by" to true +0ms
express:application set "etag" to 'weak' +7ms
express:application set "etag fn" to [Function: wetag] +2ms
express:application set "env" to 'development' +1ms
express:application set "query parser" to 'extended' +0ms
express:application set "query parser fn" to [Function: parseExtendedQueryString] +1ms
express:application set "subdomain offset" to 2 +0ms
express:application set "trust proxy" to false +1ms
express:application set "trust proxy fn" to [Function: trustNone] +1ms
express:application booting in development mode +2ms
express:application set "view" to [Function: View] +1ms
express:application set "views" to '/opt/bitnami/apache2/wm/node/views' +0ms
express:application set "jsonp callback name" to 'callback' +1ms
socket.io:server initializing namespace / +145ms
socket.io-parser encoding packet {"type":0,"nsp":"/"} +1ms
socket.io-parser encoded {"type":0,"nsp":"/"} as 0 +1ms
socket.io:server creating engine.io instance with opts {"pingTimeout":7000,"pingInterval":10000,"path":"/socket.io","initialPacket":["0"]} +0ms
socket.io:server attaching client serving req handler +10ms
Nothing appears in the log when client tries to connect to the websocket.
Can anybody point me in the right direction?
Thanks.