(Remote method call) for JavaProgramWriting real-time chat provides a good solution.
1. userinfo object: including: User ID, user name, client object (chatter) pointer. This object is created on the client. When it is connected to the server, it is sent to the service to save online user information. If it is disconnected from the server, this object will be deleted from the server online user list.
2. chatter object: This object is a client in the RMI model. But in fact, a server can call the remote method of the server to communicate with the server, the server can also use this method to communicate with the client.
3. server Object: This object is a server in the RMI model. when the client is connected to or disconnected from the server, the methods login (userinfo) and logout (userinfo) of this object are called respectively) to tell the server that a user has logged on or exited. When a client communicates with another client, send (userinfo from, userinfo to, string mess) is called to send information.