Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-16-2008, 03:13 AM
Member
 
Join Date: Dec 2008
Posts: 2
Rep Power: 0
gwaldarick is on a distinguished road
Default Multithread Chat server/client
I am interested in making a multithreaded chat client and server program.
I tried looking online for examples, but everytime i try to compile it says
"uses or overrides a deprecated API."
it doesnt even allow me to create the .class files as usual? :/
do any of you lovely people know how to make just a basic 'Multithreaded' chat system(multiple people at the same time), that will not give me deprecated API errors?

thanks in advance
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-16-2008, 12:29 PM
Senior Member
 
Join Date: Nov 2008
Posts: 265
Rep Power: 1
neilcoffey is on a distinguished road
Default
Read about ServerSocket, Socket and threads. Essentially, you create a ServerSocket on your "server" machine, then sit in a loop calling accept(). Every time that returns with a Socket, pass that socket to another thread for processing.

You'll obviously need to invent some "protocol" for how your client makes requests to the server -- what bytes/strings you send for "please log me on as X", "please tell me who's logged on", "please start a chat with Y", "please send this message to Y" etc, and think about how you'll manage e.g. chats from 1 client to multiple people. You'll also need to think about how your client "polls" for messages and/or how you handle the "two directions" of a conversation (you need to send a command to the server at a given moment, but it needs to send you a chat message at a given moment). Two connections can alleviate this, but some firewalls don't allow it.

I assume this is a small project for now. If it was a serious chat system expecting to have large numbers of clients connected, you'd have to think about using something like the Selector class to make it scale (Selector allows thousands of simultaneous connections; with a thread per connection, you'll probably max out somewhere in the low hundreds).
__________________
Neil Coffey

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-19-2008, 07:17 AM
Member
 
Join Date: Dec 2008
Posts: 2
Rep Power: 0
gwaldarick is on a distinguished road
Default Next step
Thankyou for the advice, I have refined what I am trying to accomplish.

new goal: Multiple chat clients talking to each other.
so the Server can make new threads for each connection (need some help how to do this), and can be sent a string from a client.
When it receives it from the client, it send out the message to all clients.
Anybody have any ideas on this?

imagine a chat box in a mmorpg, with all the players talking in a general/world chat.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Client/Server Chat Question Kodak07 Networking 3 03-29-2009 10:50 PM
Datagram Client and Server, client timer question saru88 Networking 1 10-05-2008 03:12 PM
[SOLVED] simple server chat program, using InputStream and OutputStream. NullPointerE jim478 New To Java 2 07-28-2008 07:32 PM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 09:18 AM
Chat Client Jessi34 New To Java 4 05-31-2007 11:37 AM


All times are GMT +2. The time now is 03:30 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org