Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda