socket.io-1.0

io.sockets.socket(socket_id).emit() - has no method 'socket'

流过昼夜 提交于 2019-11-28 01:01:24
问题 im running a nodejs server + express + socket.io version 1.0.4 and everything works as expected in my app, but i just cant emit a message from server side to client side via: socket_server.sockets.socket(socket_id).emit("message", data); when i try server throws following error: TypeError: Object #<Namespace> has no method 'socket' but i can remember that code worked on my socket.io 0.7. /0.8. projects What am i doing wrong? :( a snippet out of my app.js (nodejs server): var express = require

Sending message to a specific ID in Socket.IO 1.0

血红的双手。 提交于 2019-11-27 10:15:58
I want to sent data to one specific socket ID. We used to be able to do this in the older versions: io.sockets.socket(socketid).emit('message', 'for your eyes only'); How would I go about doing something similar in Socket.IO 1.0? In socket.io 1.0 they provide a better way for this. Each socket automatically joins a default room by self id. Check documents: http://socket.io/docs/rooms-and-namespaces/#default-room So you can emit to a socket by id with following code: io.to(socketid).emit('message', 'for your eyes only'); In socket.io 1.0 you can do that with following code: if (io.sockets

How to get room's clients list in socket.io 1.0

不问归期 提交于 2019-11-27 04:28:37
I can get room's clients list with this code in socket.io 0.9. io.sockets.clients(roomName) How can I do this in socket.io 1.0? Michael Consider this rather more complete answer linked in a comment above on the question: https://stackoverflow.com/a/24425207/1449799 The clients in a room can be found at io.nsps[yourNamespace].adapter.rooms[roomName] This is an associative array with keys that are socket ids. In our case, we wanted to know the number of clients in a room, so we did Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length In case you haven't seen/used namespaces (like