Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!