aspose file tools*
The moose likes Java in General and the fly likes Java chat application implementation method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java chat application implementation method" Watch "Java chat application implementation method" New topic
Author

Java chat application implementation method

Trevor Keast
Greenhorn

Joined: Apr 05, 2006
Posts: 4
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Trevor Keast
Greenhorn

Joined: Apr 05, 2006
Posts: 4
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java chat application implementation method