When using the socket programming, it is found that when the getInputStream method is used, the outputstream will be reported
Java.net.SocketException:socket closed Error
See the Java API written in the
Java.net.Socket.getInputStream Method:
getInputStream
Public InputStream getInputStream () throws IOException
Returns the input stream for this socket.
If the socket has an associated channel, the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking mode, the read operation of the input stream throws illegalblockingmodeexception.
Under non-normal conditions, the underlying connection may be interrupted by a remote host or network software (for example, a connection reset in the case of a TCP connection). When the network software detects an interrupted connection, the following actions are applied to the returned input stream:
The network software may discard bytes that have been buffered by the socket. The network software does not discard bytes that can be read by using reads.
If no bytes are buffered on the socket, or if read has consumed all buffered bytes, then all subsequent calls to read will throw IOException.
If no bytes are buffered on the socket, and close closes the socket is not used, available returns 0.
Closing the returned InputStream closes the associated socket.
Return:
Reads the input stream of bytes from this socket.
Thrown:
IOException-If an I/O error occurred while creating the input stream, no socket was closed, no socket was connected, or socket input was closed with shutdowninput ()
But!!!!!
I found InputStream not been shut down.
The final discovery is that the InputStream wrapper object is closed, so the conclusion is that when you still have to do the data transfer, do not try to close any of the streams.
Java.net.SocketException:socket closed