Socket.IO 1.0.x:通过id获取套接字
在0.9.x版本中,我们可以通过这样的ID获取套接字:
io.sockets.socket(socketId)
但在1.0.x中,我们不能。 如何在1.0.x中通过idfind套接字?
对于socket.io 1.0使用:
io.sockets.connected[socketId]
对于0.9的io.sockets.sockets [socketId]而不是io.sockets.socket [socketId]
你也可以使用像:
io.to(socketid).emit();
Socket.io版本2.0.3+
let namespace = null; let ns = _io.of(namespace || "/"); let socket = ns.connected[socketId] // assuming you have id of the socket