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

302
Vistas
Can't send json data over WebSocket (NODE JS)

After I created the .onopen event I made it launch some json data over, but I get an error, Here is the code:

 ws.onopen = ('connect', function(connect) {
            let obj={};
            obj.name='data'
            message = 'connect';
            obj.body=message;
            var data = {"op": 0, "d": {"server_id": serverid, "user_id": author, "session_id": sessionid, "token": tokenn, "video": true, "streams": [
                {"type": "video", "rid": "100", "quality": -1}, {"type": "video", "rid": "50", "quality": 9223372036854775807}]}}, separators=(",", ":");

            ws.send(data.toString())


What I get: node:events:368 throw er; // Unhandled 'error' event ^

Error: read ECONNRESET at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20) Emitted 'error' event on WebSocket instance at:

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

0

Use "JSON.stringify(data)" for convert Object to string

about 4 years ago · Juan Pablo Isaza Denunciar

0

I am not entirely sure this is your problem as the error looks unrelated.

But data.toString() will simply return "[object Object]". You need to use JSON.stringify(data)

ECONNRESET usually means that the connection was unexpectedly closed. Maybe your server receives your payload and closes the connection somehow because it is [object Object] and not valid JSON?

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