Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
WebSocket connection to "wss://my_amazon_ec2_machine" failed

I have updated my website by making the domain name point to cloudflare servers, then, have cloudflare point to my webhost. Before changing the website from http to https and from us ws to wss, everything was working fine, but after, it kept of saying "WebSocket connection to "wss://server" failed".

Client Side:

ws = new WebSocket('wss://ec2-3-97-91-10.ca-central-1.compute.amazonaws.com:443');

Server Side:

const express = require('express');
const https = require('https');
const WebSocket = require('ws');
const fs = require('fs');

var privateKey  = fs.readFileSync('SSL PRIVATE KEY.key', 'utf8');
var certificate = fs.readFileSync('SSL CERTIFICATE.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};



const port = 443;
var Application = express();
const server = https.createServer(credentials, Application);


var wss = new WebSocket.Server({ server })




wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(data) {
    wss.clients.forEach(function each(client) {
      if (client !== ws && client.readyState === WebSocket.OPEN) {
        client.send(data.toString());
      }
    })
  })
})

server.listen(port, function() {
  console.log(`Server is listening on ${port}!`)
})

The SSL certificate and private key are gotten from cloudflare.

If you want the full code, I uploaded it to a github repo here: https://github.com/stampixel/stampixel.ga

The domain im using is https://stampixel.ga

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda