Created
May 9, 2011 11:20
-
-
Save iamkristian/962370 to your computer and use it in GitHub Desktop.
TCP: socket programming - remmeber to shutdown in/out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... extract */ | |
public void stopServer() { | |
try { | |
socket.close(); | |
} catch (Exception e) { | |
logger.warn("An exception occured closing the socket", e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... 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