Clients wont connect to secure websocket

August 30, 2017 130 views
Networking Debian

The problem:

Hey! I've just configured SSL so I can have secure websocket (wss) on my server. But everytime the clients tries to connect to the server I get this error message:

WebSocket connection to 'wss://' failed: Error during WebSocket handshake: Unexpected response code: 200

It worked before I had SSL without problems. Now it wont even connect.

My Code:

Server.js (node.js websocket server using ws library):

const https = require('https');
const fs = require('fs');

var privateKey = fs.readFileSync('./key.pem', 'utf8');
var certificate = fs.readFileSync('./cert.pem', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

//pass in your express app and credentials to create an https server
var httpsServer = https.createServer(credentials, app);

var server = require("ws").Server;
var s = new server({ server: httpsServer })


var sock = new WebSocket("wss://");

Note: I don't have NGINX but I am willing to do everything in order to get this to work, for example change to ubuntu instead of debian,

Be the first one to answer this question.