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

103
Views
Autorizar conexión websocket con ws.js

Actualmente estoy tratando de escribir un conector websocket entre el servidor y un cliente exclusivo para el intercambio de información en tiempo real entre los dos usando ws.js. Me gustaría que el servidor le pida automáticamente al cliente la autenticación, lo que tengo se ve así:

 const ws = require("ws"); const pass = "1234" class WebsocketHandler { constructor(port = 8080) { this.server = new ws.Server(); this.server.on("connection", this.startHandleConnection.bind(this)); } startHandleConnection(wsc) { this.wsc = wsc; //Authorize the client with a password before accepting the connection wsc.on("message", this.handleMessage.bind(this)); wsc.send("Authorize"); // The client-side is expected to respond with the password } handleMessage(message) { if(!this.authorized && message !== pass) { delete this.wsc; } else { //do stuff } } }

¿Hay un enfoque más elegante para esto?

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