How can we implement a private message system (client to client) using Websockets (and PHP)?
From what I understood, the server broadcasts the message and all of th
When a client sends a messages (ws.send( message );
) your WebSocket server will receive the message. The sockets that then you send that on to is determined entirely by your server code - your implementation.
To create a one-to-one chat you need a way of routing data between just the two clients involved in the chat. You also need a way of authenticating that only those two clients can receive that information.
WebSocket frameworks tend to provide an additional PubSub layer e.g. Pusher (who I previously worked for) do this using channels. You will find similar terminology along with 'subjects' and 'topics'.
Once you have a way of routing data (chat messages) between just two clients you then need to consider authenticating the subscription. More information can be found on that via this question which asks How do I create Private channel between two user. The question is about Ruby but is applicable to any technology.