Im trying to build a small chat application where i could send private message(not broadcasting to all). to a selected socketid. I went through the documentation of SockeIO and could find a solution which works. The application works well because i tested it using a broadcasting event an all connected sockets received the emitted message. How to achieve personal messaging?.
This is the code i have tried.
socket.to(sockets[data.receiver]).emit('receive',data.message);
Where i have used the socket.to().emit('hey', 'I just met you'); example given in socketio docs and sockets[data.receiver] gives out the socket.id of the person which the message to be sent.
via Madushika Perera
No comments:
Post a Comment