aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Socket Architecture questions 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 » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Socket Architecture questions" Watch "Socket Architecture questions" New topic
Author

Socket Architecture questions

Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 67
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!

Best Regards!


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

4 extra threads? Seems a little excessive to me!

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).

- Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 67
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.

Thanks again!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Socket Architecture questions