• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

85
Vistas
Configure websocket always to be open

I use this code to connect to NodeJS web socket:

useEffect(() => {      
        let futureResponseFeedAddress = "ws://localhost:/endpoint";
        const futureResponseClient = new W3CWebSocket(futureResponseFeedAddress);
        props.onUpdateOrderbookWebsocket(futureResponseClient);
        futureResponseClient.onopen = () => {
            console.log("WebSocket Client Connected on " + futureResponseFeedAddress);
        };
        futureResponseClient.onmessage = (message) => {
            ..............
        };
        futureResponseClient.onclose = closeEvent => {
            console.log("response messages websocket closed.");
        }

        return function cleanup() {
            futureResponseClient.close();
        };
    }, []); 

But after around 1-2 minutes the messages are not received. Looks like I get timeout. Do you know how I can configure the web socket to be always open?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

My suggestion is you should use socket.io for doing any real-time communication . It uses http long polling ,upgrades the connection to websocket if needed and it has also good browser support . It is much realiable too. But there are some drawbacks , your server need to use socket.io server api .

Socket.io-client

Socket.io-server

There is no need to re-invent the wheel .

almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda