private message using websockets

前端 未结 1 1972
广开言路
广开言路 2021-01-13 20:58

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

相关标签:
1条回答
  • 2021-01-13 21:30

    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.

    0 讨论(0)
提交回复
热议问题