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

303
Vistas
Chrome WebSocket connection closes immediately

I have been trying to setup a wss server using nodejs, and have encountered a problem when trying to connect to it using chrome. The problem still occurs with all extensions disabled and in an incognito window so I've ruled that out as the problem.

When trying to connect using chrome, I get the error:

WebSocket connection to 'wss://www.domain-name.com/' failed:

with no reason given. On the server, socket.on('close') is called immediately with description "Connection dropped by remote peer" The close event has wasClean = false. This error does not occur when connecting from safari and Firefox so I'm not really sure where to look to see what's causing it. It's running on AWS Lightsail, and through an Apache proxy server.

The client code:

var socket = new WebSocket("wss://www.domain-name.com", 'JSON')
socket.onopen = function (event) {
    console.log('open');
    socket.send('socket opened')};

socket.onclose = function (event) {
    console.log(event)};

socket.onmessage = function(message) {
    console.log('receiving message from server...')};

And the server code:

const WebSocketServer = require('websocket').server;
app = express()
var server = app.listen(3000, () => {
    console.log('Server started');
});

app.use(express.static('public'));

var wsServer = new WebSocketServer({
    httpServer: server
});

wsServer.on('request', function(request){
    console.log('New connection');
    var connection = request.accept(null, request.origin);

    connection.send('welcome from server...');

    connection.on('message', function(message){
        console.log(message)};

    connection.on('close', function(reasonCode, description) {
        console.log('disconnecting', reasonCode, description);
        });
});

I also got the same error before switching to a secure WebSocket server. Any help would be appreciated, I've run out of places to look and ways to try and get more information to help out what the problem is.

EDIT: it seems to work on chrome on my phone, but not on chrome on my friends phone?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem was not specifying the protocol when accepting the connection. After about 20 hours working on the same bug and implementing an SSL certificate to get it to work, I changed:

request.accept(null, request.origin);

to:

request.accept('json', request.origin);

For some reason the chrome gives a really unhelpful error message. Microsoft edge the same error occurs, but gives a much more helpful error message so I could work out what was going on.

about 4 years ago · Juan Pablo Isaza Denunciar
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