Hi I'm currently studing one good way to implement my server socket with a multiclient feature. If i am not getting crazy i think that samples found in Google says something like this (or i'm not understand i hope):
One Thread to accept();
for each client connection 4 new different Threads : 2 for Server side to handle request and response and 2 For client too for handle request and response too.
Its have to work by this way?
I dont want to get code ready, just find a way to implement this feature if anybody can post me a link or stuff will be very appreciate!
Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
It is possible to have the client using a single thread (the thread that is started by the JVM to run the main method) - there is no need to explicitly create any threads on the client side.
On the server side, you can have the main server thread (again, the one started by the JVM) doing the listening. Then for each client that connects, you only need to create one thread to perform the server tasks.
Take a look at the Sun Sockets tutorial for an example of all this - they start of with a simple server that does not create any threads at all, then build up to the point where they have a server thread per connected client.
The only reason I can think of that you might want to create an extra thread on the client side is if you wanted your client application to remain responsive while waiting for the server. Note that this can cause all sorts of additional issues that will need to be catered for, and is not in the requirements. Given that adding this in will not gain you one extra mark in the assignment, and if you fail to cover all the additional issues correctly you might actually loose marks - so my recommendation would be to ignore this issue (and maybe make a note of it in the choices documentation).
Thanks for your reply Andrew. I had thought about keeping the same object Socket obtained with the method accept() throughout the lifecycle of the client application. But it seems very difficult to maintain and i get mutch more problems with this.