Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

socket.accept() + socket.close()

 
Luiz Reginaldo Curado
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to close my server socket, but my server thread is blocked in the accept() call. In my implementation I call close() and a Socket Exception is throwed. Is this the correct way to stop my server?

public void startServer() {
try {
...
socket.accept() ;
...
} catch( SocketException e ) {
e.printStackTrace() ;
}
}

public void stopServer() {
...
socket.close() ;
...
}
 
chris bajada
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is the correct way to stop the server. The SocketException is thrown, as the socket can no longer listen for incoming client connections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic