I am currently writing a chatroom program in Java. There is a server that handles all the client connections and one main display where all the talking takes place. One feature I want to include is a constantly updating list of all the users in the chatroom in the sidebar. However, the way the program works is that the client opens a character stream with the server and data is sent back and forth that way.
Right now, any characters sent to the server from the client is relayed to all the clients and put on the main display. However, I want to send information to the client from the server about the list of users. How would I be able to differentiate between the userlist information and main display information?
1- You can have two lines of communication. A line( a socket connection ) will accept the incoming events for users list. The other line will accept information used for the main display. It is better to not to open many connections to the server because you need to open more ports or handle multiple connections from a single client on one port.
2- You can use control flags or message types so you can distinguish the type of message you are receiving from the server. When it is related to updating the users list you do so and when it is about displaying something on the main board, you display it.