Clients wont connect to secure websocket

#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,

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

i solved this by allowing lover https protocols on server.

When creating https server just change minVersion setting to tlsv1.

İ hope it helps.

Sorry to see that your question hasn’t received an answer yet. Your code seems to match the official SSL example, so the only thing that seems off is that the port is not specified in this command:

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