Common reasons for Connection reset by peer

1. If the Socket at one end is closed (or actively closed, or closed due to abnormal exit), the other end still sends data, and the first data packet sent will cause this exception (Connect reset by peer).

The Socket is connected for 60 seconds by default. If there is no heartbeat interaction within 60 seconds, that is, reading and writing data, the connection will be automatically closed.

2. One end exits, but the connection is not closed when exiting, and the other end throws this exception (Connection reset) if it reads data from the connection.

Simply put, it is caused by read and write operations after the connection is disconnected.

Common reasons for Connection reset by peer:

1) The number of concurrent connections of the server exceeds its carrying capacity, and the server will close some of these connections;
if it is known that the number of concurrent clients actually connecting to the server does not exceed the carrying capacity of the server, it may be a virus or Trojan horse, causing network traffic abnormal. You can use netstat -an to view network connectivity.
2) The client closes the browser, but the server is still sending data to the client;
3) The browser presses Stop;
these two situations generally do not affect the server. However, if the exception information is not handled specially, the exception may appear repeatedly in the log file of the server, causing the log file of the server to be too large and affecting the operation of the server. For the part that caused the exception, use try...catch to catch the exception, and then do not output or only output a prompt message, avoid using e.printStackTrace(); to output all exception information.
4) The problem of the firewall;
if the network connection passes through the firewall, and the firewall generally has a timeout mechanism, when the network connection does not transmit data for a long time, the TCP session will be closed, and then reading and writing will cause an exception. If you turn off the firewall and solve the problem, you need to reconfigure the firewall, or write your own program to implement a long TCP connection. To realize the long connection of TCP, you need to define the heartbeat protocol by yourself, and send the heartbeat protocol every once in a while, and the two parties maintain the connection.
5) JSP buffer problem.
The default cache of JSP pages is 8k. When the data of the JSP page is relatively large, it is possible that the JSP is not completely transmitted to the browser. At this time, the size of the buffer can be adjusted appropriately.

The first exception is java.net.BindException:Address already in use: JVM_Bind.

This exception occurs when the server performs a new ServerSocket(port) (port is an integer value of 0, 65536) operation. The reason for the exception is that a port that is the same as port has been started and is listening. At this point, use the netstat -an command to see a port in the Listending state. Just find a port that is not occupied to solve this problem.

The second exception is java.net.ConnectException: Connection refused: connect.

This exception occurs when the client performs the new Socket(ip, port) operation. The reason for the exception is that either the machine with the ip address cannot be found (that is, the route from the current machine to the specified ip does not exist), or the ip exists, but the specified port could not be found to listen on. If this problem occurs, first check whether the ip and port of the client are wrong. If they are correct, ping the server from the client to see if they can ping. , then see if the program listening on the specified port on the server side is started, this will definitely solve this problem.

The third exception is java.net.SocketException: Socket is closed, which may occur on both client and server.

The reason for the exception is that the network connection is read and written after the user has actively closed the connection (calling the close method of the Socket).

The fourth exception is java.net.SocketException: (Connection reset or Connect reset by peer:Socket write error).

This exception may occur on both the client side and the server side. There are two reasons for this exception. The first is that if the Socket on one end is closed (or actively closed or closed due to abnormal exit), the other end still sends data, the first packet sent raises this exception (Connect reset by peer). The other is that one end exits, but the connection is not closed when exiting, and the other end throws this exception (Connection reset) if it is reading data from the connection. Simply put, it is caused by read and write operations after the connection is disconnected.

The fifth exception is java.net.SocketException: Broken pipe. This exception can occur on both client and server.

在第4个异常的第一种情况中(也就是抛出SocketExcepton:Connect reset by peer:Socket write error后),如果再继续写数据则抛出该异常。前两个异常的解决方法是首先确保程序退出前关闭所有的网络连接,其次是要检测对方的关闭连接操作,发现对方关闭连接后自己也要关闭该连接。

客户端错误代码10053 Software caused connection abort(软件原因导致连接中断)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324629536&siteId=291194637