Java Socket and ServerSocket Issue -


i have code snippet:

serversocket serversocket=new serversocket(defaultport); serversocket.setsotimeout(1000); socket socket=serversocket.accept(); 
  1. does closing serversocket object affects state of socket object?

  2. if close serversocket object can still use socket 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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -