Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java chat application implementation method

 
Trevor Keast
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

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?

Thanks in advance for your comments.

Trevor
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow... there is a lot of questions... but I'll take a shot at one of them.

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?


Sure, why not? Keeping it updated is pretty simple. When a client disconnects, it should generate an exception of some sort on the socket. Just make sure that updating the client list, be one of the clean up actions to do.

Or better yet. You can also work in some sort of disconnect command into the chat protocol.

Henry
 
Trevor Keast
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry,

So if I create an array of user settings objects on every client how can I steam that data over the network? I'm using a buffered reader and printwriter for the conversation text and that was pretty easy to set up. If I send the user settings list to the clients in this fashion I need to somehow separate that information from the conversation text being sent.

I was thinking about adding a prefix to everything that is sent out by the server and clients so that its easy to distinguish between differnt types of data.

Do I need to use serializable?

Thanks again

Trevor
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic