socket.io chat with private rooms

前端 未结 2 512
天命终不由人
天命终不由人 2021-01-30 03:07

I started looking into node and socket.io.

I already have created a simple chat application and I am amazed at how easy it was.

Now, I would like to take a littl

相关标签:
2条回答
  • 2021-01-30 03:10

    Hej Thomas

    if theres only 2 users talking you dont need use publish att all just send that message from the client to the server and let the server locate the other client and send it down.

    0 讨论(0)
  • 2021-01-30 03:33

    If the only functionality you want is for two people to be able to send messages to one another (and not groups of people to have a room), then the logic could be something like this:

    1. When a user connects, store their connection in an object keyed by their username (or in any other data structure that ensures you can find a specific user's connection).
    2. When a Bob wants to talk to Jeff, send the server an event stating such.
    3. The server looks up Jeff's Socket.IO connection in the object from step 1.
    4. The server uses this connection to send Jeff (and only Jeff) the private message.
    0 讨论(0)
提交回复
热议问题