How to close java client socket correctly?
What should be the sequence of calls (before|after) socket.close()?
The Socket documentation states:
Closing this socket will also close the socket's InputStream and OutputStream.
You don't have to shutdown the input/output. However that does allow you to "half" close the socket. Say if you wanted to continue to send data, but want to indicate you will no longer receive it.
So in short; It's completely fine to do the following:
...
finally {
if (socket != null)
socket.close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.