By southsweden
#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://138.68.86.134/' 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);
httpsServer.listen(8443);
var server = require("ws").Server;
var s = new server({ server: httpsServer })
Client:
var sock = new WebSocket("wss://138.68.86.134");
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,
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!
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://138.68.86.134");
i solved this by allowing lover https protocols on server.
When creating https server just change minVersion setting to tlsv1.
İ hope it helps.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.