Java Socket and ServerSocket Issue -
i have code snippet:
serversocket serversocket=new serversocket(defaultport); serversocket.setsotimeout(1000); socket socket=serversocket.accept();
does closing
serversocket
object affects state ofsocket
object?if close
serversocket
object can still usesocket
object streams?
the short answers are:
1) no
2) yes
the longer answer is:
the serversocket waits clients connect (he waits in accept-method). when there client, accept-method returns, more returns socket-object represents server's endpoint of server-client connection. if server closes server-socket, no longer listens (he no longer accepts new clients) clients has socket-connection unaffected.
your code not "wrong" per se, capable of accepting single client , if connected within 1000 milliseconds.
here introduction including sample code:
http://download.oracle.com/javase/tutorial/networking/sockets/clientserver.html
Comments
Post a Comment