Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

401
Vistas
Socket.IO 4.0.1: Get socket by id

I used

const my_socket = io.sockets.connected['YnwlYH-gCKT2K9jEAAAu'];

a lot.

https://stackoverflow.com/a/24464450/1707015

Is it broken in 3.X and 4.0.1?

$ npm list socket.io
socket.io@4.0.1

$ npm list socket.io-client
socket.io-client@4.0.1
# Object.keys(io.sockets):
_events,_eventsCount,_maxListeners,sockets,_fns,_ids,server,name,adapter

# io.sockets.connected:
undefined

# io.sockets.connected['YnwlYH-gCKT2K9jEAAAu']:
TypeError: Cannot read property 'YnwlYH-gCKT2K9jEAAAu' of undefined
    at Socket.<anonymous> (/path:row:char)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)

I can get it run with version 2 (instead of 3 or 4):

$ npm install --quiet --save-dev socket.io@2.X socket.io-client@2.X

Yes, this is literally an X - for the newest sub version.

Do you have any refactoring instructions?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This question and answer is probably a (newer/better) duplicate of https://stackoverflow.com/a/66835961/1707015. Sorry, I only saw it now. Credits to Sanjay Nishad.


const my_socket = io.sockets.sockets.get('YnwlYH-gCKT2K9jEAAAu');
over 4 years ago · Santiago Trujillo Denunciar

0

"socket.io": "^4.1.3"

nsp.sockets.get(socketid).join(roomId)
nsp.to(roomId).emit("message",{message : "something"})

it worked for me

over 4 years ago · Santiago Trujillo 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda