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

122
Visualizações
multiple browser instances with websocket capabilities in node?

Let's say I am building a social app. I want to log into multiple accounts (one per browser instance) without an user interface (all via node), and by calling all respective endpoints to log in and start chatting.

The important part is to test when an user closed the tab or logs out or leaves the group and therefore the websocket's connection closes.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I understand you correctly. You would like to make a server-side event happen whenever a client connects or disconnects, without any html,css.... or any other user interface. You can do it like this in node :

For connection you use :

Server.on("connection,function(ws){some stuff...})

The function that is called on connection will get the websocket that connected as parameter by default. I just use a lambda function here you can also call one that will then get the websocket as parameter.

For disconnection you put a function in the Server.on function to monitor when the client disconnected. Like this :

Server.on("connection,function(ws){
  ws.onclose = function (ws) { 
  some stuff...
    }
})

You can again replace the lambda function by another one. Server is in my case equal to this :

const wsserver = require("ws").Server
const server = new wsserver({ port: someport })

But it can vary. All you need to do apart from that is connect the client. I do it like this but it can vary as well.

const ws = new WebSocket("ws://localhost:someport");

I hope this is helpful.

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