java.io.IOException broken pipes

java tcp / ip abnormal

1 java.net.SocketTimeoutException . 

This anomaly is more common, socket timeouts. Generally there are two places will throw this one is connect time, the timeout parameter of connect (SocketAddress endpoint, int timeout) in the latter to decide, there is setSoTimeout (int timeout), this is set to read timeout. They are set to 0 represents infinity.

 

2 java.net.BindException:Address already in use: JVM_Bind 

The abnormality occurs in the server-side new ServerSocket (port) or socket.bind (SocketAddress bindpoint) operation.

The reason: the port as a port has been started, and monitor. At this time, with the netstat -an command, you see a Listending port state. Just find an unoccupied port will be able to solve this problem.

 

3 java.net.ConnectException: Connection refused: connect

The exception occurs in the client new Socket (ip, port) or socket.connect (address, timeout) operation, because: a machine specified ip address can not be found (that is to say from the current machine does not exist to the specified ip route), or the ip exists, but can not find the specified port for monitoring. Should first check whether the client's ip and port wrong, whether if properly from the client ping the server can ping to see if can ping (ping service on the server side to cut out the need for additional measures), then look at listening on the specified port of the server program is started.

 

4 java.net.SocketException: Socket is closed 

The exception may occur in both the client and the server. Cause of the abnormality is one's own initiative to close the connection (called Socket close method) and then the network connection to read and write.

 

5 java.net.SocketException: Connection reset 或者Connect reset by peer:Socket write error

The abnormality may occur in both the client and the server, there are two, the first one is, if one end is closed Socket (active or off, or because of abnormal exit caused closed) causes the exception, and the other end is still sent data, the first data packet transmitted from the initiator exception (Connect reset by peer). Another is the exit end, but does not close the connection upon exiting the other end be thrown if the data read from the connection (Connection reset). Simply means that the read and write operations after the disconnection caused.

In another case, if an end of transmission interrupt RST packet of the TCP connection, the other end of this exception will occur, if tomcat, the following exception:

org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer

Ali tcp health check mode for performance improvement, eliminating wave interaction, sending a RST directly connected to a final break, this will lead to a server side anomaly;

For servers, the general reasons can be considered:

Number of concurrent connections a) the server exceeds its carrying capacity, some of which will be connected to the active server is Down.

b) during the data transmission, the receiving client browser or closed, and the server also transmits data to the client.

 

6 java.net.SocketException: Broken pipe

The exception may occur in both the client and the server. Thrown SocketExcepton: Connect reset by peer: Socket after write error, and then continue to write data if Thrown. The first two anomalies solution is to first make sure to close all network connections before the program exits, followed by closing the connection to detect each other's operations, we found each other after closing the connection we also have to close the connection.

 

For exceptions in both cases 4 and 5, require special attention to maintain the connection. Fortunately, if long connection, connection status for improper maintenance, it is very likely to occur in a short abnormal connection. Basically for long connection to do it is:

 

a) detecting the other active disconnected (they call Socket close method). Active disconnected because the other side, if the other party during a read operation, at this time, the return value is -1. Therefore, upon detection of the disconnection each other, the one's own initiative to close the connection (call close the Socket).

 

b) to monitor their downtime, abnormal exit and the network is, the general practice is the heartbeat. Both periodically transmit data to each other, but also receives the "heartbeat data" from each other, if several consecutive cycles does not receive a heartbeat, it may be determined, or other abnormal or down an exit or the network is, at this time also requires active Close own connection; if the client can initiate the connection again after a certain time delay. Although there is a Socket keep alive the option to maintain the connection, if using this option, it normally takes two hours to find each other down, the abnormal exit and the network is disconnected.

 

7 java.net.SocketException: Too many open files

The reason: The maximum number of open file handles in the operating system due to limited, often occurs in many concurrent users access the server's time. Because in order to execute each user's application server must load a lot of files (new a socket requires a file handle), which will lead to a lack of open file handle.

Solution:

a) Try to class labeled jar package, as a package consumes only a jar file handle, if not packaged, a consumption class to a file handle.

b) java GC can not close the file handle of open network connections, if not performed close () the file handle will always exist, it can not be closed.

It can also be considered to set the maximum number of open socket to control this problem. Operating system do the relevant settings, increase the maximum number of file handles.

ulimit -a can view the current system resource limits, ulimit -n 10240 can be modified, this modification is only valid for the current window.

 

8 Cannot assign requested address                         

1. The port number is occupied, leading to address not binding:

java.net.BindException: Can not assign requested address: bind: Since the IP address is caused by changes;

2. The server network configuration exception:

/ Etc / hosts configured address error;

3. Another is executed ipconfig found no loop address, because the loop address configuration file is missing;

Guess you like

Origin blog.csdn.net/qq_34730511/article/details/82216406