Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Socket Architecture questions

Ranch Hand
Posts: 80
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
author and jackaroo
Posts: 12199
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Julio Cesar Marques
Ranch Hand
Posts: 80
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic