wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Qn regarding sockets in SCJD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Qn regarding sockets in SCJD" Watch "Qn regarding sockets in SCJD" New topic
Author

Qn regarding sockets in SCJD

subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
I was reading Andrews SCJD book and I have a little confusion
DvdSocketServer is responsible to handle socket connections


The followign code forks a thread for every socket accepted thereby supporting multiple clients to connect simultaneously







My confusion is why is DVDSocketServer extending Thread? Cant it be a main application that accepts connection and forks out
a thread


Below is source code from suns site for the same






Cheers
Priya
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Subu,

That is an interesting question. I will try to guess at what Terry was attempting to achieve.

The KKMultiServer code blocks within the server/user-interface itself. That is, once it gets to the serverSocket.accept() call, the server just waits for somebody to connect - it no longer accepts any keyboard commands, and there is no way to exit the program short of killing the server.

The NetworkStarterSockets class that Terry wrote has the potential to give a better user experience. It is possible that the user interface itself could remain responsive, while the DvdSocketServer handles the listening for new connections / spawning new threads. As an example of what might be possible the NetworkStarterSockets does not persist the configuration until after it has registered a DvdSocketServer.

I am curious why you copied all that code from Sun - did you have an additional question? From my perspective, the only really equivalent sections from your posting are:
subu ananthram wrote:
The followign code forks a thread for every socket accepted thereby supporting multiple clients to connect simultaneously

Below is source code from suns site for the same


Change the writing styles and these 2 blocks would be the same. Personally I don't like the embedding of the accept() call [which blocks] within the instantiation of the KKMultiServerThread class, and I don't like the lack of braces, but that is just stylistic differences. The 2 code blocks are functionally equivalent.

It is the section that you didn't quote (the registering / starting of the DvdSocketServer class) that may have been more contextually relevant to your question.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Qn regarding sockets in SCJD
 
Similar Threads
sockets and printwriting
Socket : MultiClient Server
client / server (communication problem...)
2 JavaTutorial Errors quick fix
applet loading forever...