Help with Network Program

Z

zymosisus

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
 
C

Chris Smith

zymosisus said:
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

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Z

zymosisus

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
 
C

Chris Smith

zymosisus said:
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.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top