2014-11-21 5 views

Antwort

27

Für socket.io 1.0 Verwendung:

io.sockets.connected[socketId] 

Für 0.9 seine io.sockets.sockets [SocketId] und io.sockets.socket nicht [SocketId]

+0

Danke, es funktioniert –

+0

Für Namespace-Verbindungen konnte ich nicht über 'io.sockets.connected [socketId] .emit()' darauf zugreifen, aber es funktioniert ähnlich 'var nsp = io.of ('/ my-namespace'); 'dann' nsp.connected [socketId] .emit() '. Vielen Dank – Luckylooke

12

Sie können auch wie verwenden:

io.to(socketid).emit(); 
0

Socket.io Version 2.0.3+

let namespace = null; 
    let ns = _io.of(namespace || "/"); 
    let socket = ns.connected[socketId] // assuming you have id of the socket