Swoole Instant messaging Perplexity

1. Suppose you use swoole to make a web version of Wechat, and the client uses websocket to connect to the server
2. How to realize the private chat of friends (1 to 1), without writing the dead server port
3. Not writing the port means that the server has multiple ports to provide services; if A wants to chat with B 1-to-1, then A may connect to port an and B to port B. when A sends a message to B, how does the server know which tcp connection B is under?

Jun.25,2021

write a function that maps userID to port
such as the simplest

  

make a userid to client mapping in the cloud or memory. The sending packet carries the userid, to be sent and pushed to the client of the response according to the mapping

.
Menu