I am new here and am hoping that you may be able to give me a few pointers.
I am writing a chat application in Java. I have one server which starts a new thread for each new client that connects. So far all pretty straight forward.
I have a client that connects to the server and sends over a username. The username is stored in the new thread instance. This way the server can distribute the chat name as well as the conversation text to all the clients so everyone knows who is talking.
That general chat bit works great but I want to have a list on every client that is always up to date containing the names of all users currently online. I also want to add extra functionality like text color perhaps.
What approach should I take to achieve this?? What would be the most sensible way of doing it?
I am using text streams to send all this information between server and clients. How can I separate the "conversation text" from all streams that contain system information like a users text colour?
Should I keep a list off all current users on every client and store everyones settings in there? If I do this how can I keep it updated?
You would just pre-pend "headers" to the beginning of your message and pull them off when they are received on the client - something like -
When you receive one of these messages on a client, pull it apart using the separators ":[," (maybe using StringTokenizer). Look at the first "header" to figure out what kind of message it is - if it's a "MESSAGE", the first parameter says what user sent it, look in the user table to get the color, and print the "message text" section to the screen. If it's a "USER_LIST" - pull all the username/color pairs out of the message and update the user table. If it's a USER_ADDED or USER_REMOVED pull the parameter off and adjust the user table accordingly.