Skip to content

Instantly share code, notes, and snippets.

@iamkristian
Created May 9, 2011 11:20
Show Gist options
  • Save iamkristian/962370 to your computer and use it in GitHub Desktop.
Save iamkristian/962370 to your computer and use it in GitHub Desktop.
TCP: socket programming - remmeber to shutdown in/out
/* ... extract */
public void stopServer() {
try {
socket.close();
} catch (Exception e) {
logger.warn("An exception occured closing the socket", e);
}
}
/* ... extract */
public void stopServer() {
try {
try {
socket.getOutputStream().flush();
socket.shutdownOutput();
} catch (Exception e) {
logger.warn("An exception occured during shutdown of output: ", e);
}
try {
socket.shutdownInput();
} catch (Exception e) {
logger.warn("An exception occured during shutdown of inpput: ", e);
}
} catch (Exception e) {
// This can't happen
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
logger.warn("An exception occured while closing socket", e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment