Java.net.SocketException:socket closed

Source: Internet
Author: User
Tags connection reset

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.