Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Help with Network Program

Thread view: 
zymosisus - 12 Oct 2005 13:17 GMT
Hello everyone,

I've got this great idea for a program but don't really know how to get
going on it.  I am essentially working on a "Chat" Program.  I've
created a simple basic command line chat program where one computer
acts as a "Server" and a client connects to it over the network.  The
two computers can then send messages back and forth to the other.  This
basically follows the Sun Java example (KnockKnockServer and
KnockKnockClient).  Now comes for the customization that I don't really
know where to begin.  I want multiple clients to connect to the
"Server", and when the "Server" ask the clients a question all the
clients get the same question.  When the clients get the question they
can answer multiple times until the user at the "Server" stops
accepting answers.  Then the Clients' last answer is recorded.

My question is basically "how?"  I've tried to create different threads
(java.sun KKMultiServer) but this isn't really what I want and I don't
know how to change it to make it what I want.  Does anyone have any
Ideas, or where I should look for answers?

Thanks,
Drew Thomas
Chris Smith - 12 Oct 2005 15:29 GMT
> My question is basically "how?"  I've tried to create different threads
> (java.sun KKMultiServer) but this isn't really what I want and I don't
> know how to change it to make it what I want.  Does anyone have any
> Ideas, or where I should look for answers?

You seem quite convinced that you don't want different threads.  Why?  
Any straight-forward Java implementation of the application you describe
would use multiple threads.  Before someone invents some kind of trick
to avoid the need for threads, it's probably best if you clarify why you
are trying to avoid them.

Aside from that, your question is quite vague.  All I can say is to look
into the API docs for:

   java.net.ServerSocket
   java.net.Socket

and perhaps:

   java.io.DataInputStream
   java.io.DataOutputStream

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

zymosisus - 12 Oct 2005 15:46 GMT
Sorry,  I didn't mean to make it sound like I don't want to use
threads.  What I ment when I said that it wasn't what I wanted was that
the solution didn't work for me.  It allowed me to have multiple
connections, but each connection was handled seperatly.  In other words
a different conversation per connection.  I couldn't get the same
message to go to each thread.  

Thanks,
-Drew
Chris Smith - 12 Oct 2005 21:03 GMT
> Sorry,  I didn't mean to make it sound like I don't want to use
> threads.  What I ment when I said that it wasn't what I wanted was that
> the solution didn't work for me.  It allowed me to have multiple
> connections, but each connection was handled seperatly.  In other words
> a different conversation per connection.  I couldn't get the same
> message to go to each thread.  

You need to handle each connection separately.  Whether you arrange for
the same content to be sent over each connection is up to you, but
you'll eventually need to make separate calls to OutputStream or NIO
Buffer objects for EACH of your connections.  These objects ultimately
-- at some level of indirection -- handle things like addressing packets
and dealing with buffering and congestion, which will be a unique task
for each client.

So, somewhere in your server application you'll need a list of all
connected clients, and you'll need a loop that walks through each one of
them and arranges to send that message once per client.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.