I am using node.js and socket.io to create a chat application. How to send message to another socket, I know the id of the socket or the username only. There are no rooms , clients chat one on one.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With Socket.IO, you aren’t restricted to only using the socket object within the callback of the connection function. You can create an object that stores the socket object for a particular username and look up the socket to send a message to when a client emits a message. You would need to transmit the intended target with every message.
Example:
See more examples on the examples page of Socket.IO’s website.