SSL Connection for Websocket

I am trying to test a secure websocket, but I am having problems. Here is my test:

var WebSocket = require('ws'); describe('testing Web Socket', function() { it('should do stuff', function(done) { var ws = new WebSocket('wss://localhost:15449/', { protocolVersion: 8, origin: 'https://localhost:15449' }); ws.on('open', function() { console.log('open!!!'); done(); }); console.log(ws); }); }); 

Here is the "ws" log after it was created:

 { domain: null, _events: { open: [Function] }, _maxListeners: undefined, _socket: null, _ultron: null, _closeReceived: false, bytesReceived: 0, readyState: 0, supports: { binary: true }, extensions: {}, _isServer: false, url: 'wss://localhost:15449/', protocolVersion: 8 } 

I can’t open a magazine from open. I run the project locally, and when I use the Chrome Advanced Rest Client tool, I can connect just fine.

Am I missing something? Please, help.

Edit: I added ws.on('error') and ws.on('error') out { [Error: self signed certificate] code: 'DEPTH_ZERO_SELF_SIGNED_CERT' } I also tried following this code , but getting the same error.

+5
source share
1 answer

The https module rejects your self-signed certificate (as you would hope). You can force it to stop checking by passing the rejectUnauthorized: false parameter (which WebSocket goes to https ):

 var ws = new WebSocket('wss://localhost:15449/', { protocolVersion: 8, origin: 'https://localhost:15449', rejectUnauthorized: false }); 
+5
source

All Articles