I am creating a chatbot using socket.io. But I am facing some problems in implementation.
I want the server to respond to each client based on their request, but instead, the server broadcasts the message to all connected clients to the server.
It behaves more like a group chat, but I want to do a one-on-one chat with the backend server.
How to resolve this issue?
>Solution :
faced the Same issue few days back
For me it resolved the issue
Instead of using io.emit() or socket.broadcast.emit() methods, use the socket.emit() method to send responses back to the specific client that initiated the request. You can access the specific socket instance from the server-side socket.io object to send the response to the correct client