How does the client know its user_id and the user_id of the interlocutor? How does the initial setup happen?
sobes.tech AI
Answer from AI
The client usually receives their user_id after successful authentication on the server. Upon first connection, the client sends login data (username/password, token, etc.), the server verifies them and returns a unique user_id, which the client stores locally (for example, in memory or in localStorage for web).
The user_id of the interlocutor is learned by the client through the application interface — for example, from the contact list, chat history, or by invitation. Initially, the server provides the client with a list of available users or a specific user_id for communication.
Initialization occurs as follows:
- The client authenticates and receives their
user_id. - The client requests a list of users or a specific
user_idof the interlocutor. - After selecting the interlocutor, the client begins exchanging messages using these identifiers.
Thus, the user_id is a unique identifier assigned and controlled by the server, which the client stores and uses to identify itself and its interlocutors.