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

218
Views
socket.emit no emite mensajes al remitente
  1. 'socket.emit ' no envía mensajes al cliente que lo envió, mientras que
  2. 'socket.broadcast.emit' enviando mensajes a todos los clientes, incluido el remitente.

No puedo entender lo que me estoy perdiendo aquí. Para el segundo caso, verifiqué socket.id mientras enviaba el mensaje y lo registré cuando se recibió la respuesta, resultó ser el mismo

socket.js

 var socket = require('socket.io')(), socketApi = {}; socketApi.io = socket; socketApi.io.on('connection',(client) => { client.on('clientMessage', (msg) => { console.log('hi'); client.emit('serverMessage',msg); }) client.on('disconnect',() => { socketApi.io.emit('serverMessage','client is disconnected'); console.log('disconnected'); }) }) module.exports = socketApi;

cliente.js

 getServerResponse() { socket.on('serverMessage',(msg) => { console.log(msg); }) }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

De acuerdo con los documentos broadcast.emit envía a todos excepto al remitente y emit envía solo al remitente: https://socket.io/docs/emit-cheatsheet/ .

Estaba en el mismo problema, así que terminé llamando a ambos:

 // socket.io server io.on('connection', socket => { socket.on('message', (data) => { messages.push(data) socket.broadcast.emit('message', data) // sends to all except the sender socket.emit('message', data) // sends to the sender }) })
about 4 years ago · Santiago Trujillo 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!