last week, I met a
Connection Reset by Peer
network connection problem, for this, I searched the Chinese and english some websites, searched everywhere can find every corner, found that the principle of this situation, the Java exception on the client and the server can occur, the cause of the exception is:
Common reasons for Connection reset by peer:
1) The number of concurrent connections to the server exceeds its capacity, and the server shuts down some of the connections;
If you know that the actual number of concurrent clients connected to the server does not exceed the load of the server, it is possible that a virus or trojan, causing network traffic anomalies. You can use Netstat-an to view network connections.
2) The client has turned off the browser and the server is sending data to the client;
3) The browser side presses stop;
These two situations generally do not affect the server. However, if the exception information is not handled specifically, it is possible to duplicate the exception in the server's log file, causing the server log file too large to affect the server's operation. You can use Try...catch to catch the exception to the part that caused the exception, and then do not output or just output a single prompt message, avoid using e.printstacktrace (), and output all exception information.
4) firewall problems;
If the network connection through the firewall, and the firewall generally has a time-out mechanism, when the network connection does not transfer data for a long time, the TCP session will be closed, read and write after the shutdown, will cause an exception. If you turn off the firewall, the problem is resolved, you need to reconfigure the firewall, or you write your own program to implement TCP long connections. To implement TCP long connection, you need to define the heartbeat protocol, every time, send a heartbeat protocol, both sides maintain the connection.
5) The buffer problem of JSP.
JSP page Default cache is 8k, when the JSP page data is relatively large, it is possible that the JSP is not completely passed to the browser. The buffer size can then be adjusted appropriately. <%@ page buffer= "100k"%>
Common network exceptions (go from http://www.cnblogs.com/kaixin110/archive/2008/04/11/1148671.html):
The 1th exception is java.net.BindException:Address already in Use:jvm_bind. This exception occurs on the server side for new ServerSocket
(port) (port is a 0,65536 integer value) when the operation. The exception is due to the fact that a port is already being started and is listening. This time with
Netstat–an command, you can see a port with a listending status. Just find an unoccupied port to solve this problem.
The 2nd exception is Java.net.ConnectException:Connection Refused:connect. The exception occurs when the client makes a new Socket (IP, port)
operation, the exception occurs because either a machine with an IP address cannot be found (that is, from the current machine does not exist to the specified IP route), or the IP exists
, but the specified port is not found for listening. This problem occurs, first check the client's IP and port is wrong, if correct, ping the server from the client
See if you can ping, if you can ping the (service server side to ping off the need for another method), the server-side monitoring of the specified port program is
Start, this will definitely solve the problem.
The 3rd exception is the Java.net.SocketException:Socket is closed, which can occur on both the client and the server. The reason for the exception is that you actively shut
After the connection is closed (called the Close method of the socket), the network connection is read and written.
The 4th exception is java.net.SocketException: (Connection reset or Connect reset by Peer:socket write error). The exception
Can occur on both the client and server side, the reason for this exception is two, the first is if the socket on one end is closed (or active shutdown or
Exit), the other end still sends the data, and the first packet sent throws the exception (Connect reset by peer). The other is one end exiting
, but the connection is not closed when exiting, and the other end throws the exception if it reads data from the connection (Connection reset). The simple thing is, after the connection is broken,
Read and write operations are caused.
The 5th exception is the Java.net.SocketException:Broken pipe. This exception can occur on both the client and the server. In the first case of a 4th exception
(That is, after you throw socketexcepton:connect reset by Peer:socket write error), the exception is thrown if you continue to write the data. Top two different
The usual solution is to first ensure that the program to close all network connections before exiting, followed by detection of the other side of the closed connection operation, found that the other side after closing the connection to
Close the connection.
After analyzing the above reasons, I found that I did not solve the problem I encountered: The complete exception is as follows: 03-12 13:50:35.788:w/system.err (9801): Java.net.SocketException:recvfrom Failed:econnreset (Connection reset by Peer)
03-12 13:50:35.790:w/system.err (9801):At Libcore.io.IoBridge.maybeThrowAfterRecvfrom (iobridge.java:585)
03-12 13:50:35.790:w/system.err (9801):At Libcore.io.IoBridge.recvfrom (iobridge.java:548)
03-12 13:50:35.791:w/system.err (9801):At Java.net.PlainSocketImpl.read (plainsocketimpl.java:489)
03-12 13:50:35.792:w/system.err (9801):At java.net.plainsocketimpl.access$000 (plainsocketimpl.java:46)
03-12 13:50:35.793:w/system.err (9801):At Java.net.plainsocketimpl$plainsocketinputstream.read (plainsocketimpl.java:240)
03-12 13:50:35.794:w/system.err (9801):At Org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer (abstractsessioninputbuffer.java:103)
03-12 13:50:35.795:w/system.err (9801):At Org.apache.http.impl.io.AbstractSessionInputBuffer.readLine (abstractsessioninputbuffer.java:191)
03-12 13:50:35.796:w/system.err (9801):At Org.apache.http.impl.conn.DefaultResponseParser.parseHead (defaultresponseparser.java:82)
03-12 13:50:35.797:w/system.err (9801):At Org.apache.http.impl.io.AbstractMessageParser.parse (abstractmessageparser.java:174)
03-12 13:50:35.798:w/system.err (9801):At Org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader (Abstracthttpclientconnection.java : 180)
03-12 13:50:35.799:w/system.err (9801):At Org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader (defaultclientconnection.java:235)
03-12 13:50:35.800:w/system.err (9801):At Org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader (abstractclientconnadapter.java:259 )
03-12 13:50:35.801:w/system.err (9801):At Org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse (httprequestexecutor.java:279)
03-12 13:50:35.802:w/system.err (9801):At Org.apache.http.protocol.HttpRequestExecutor.execute (httprequestexecutor.java:121)
03-12 13:50:35.803:w/system.err (9801):At Org.apache.http.impl.client.DefaultRequestDirector.execute (defaultrequestdirector.java:431)
03-12 13:50:35.804:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (abstracthttpclient.java:555)
03-12 13:50:35.805:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (abstracthttpclient.java:487)
03-12 13:50:35.806:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (abstracthttpclient.java:465)
03-12 13:50:35.806:w/system.err (9801):At Com.hb56.DriverReservation.android.net.MyHttpHelper.doRequestForEntity (myhttphelper.java:210)
03-12 13:50:35.807:w/system.err (9801):At Com.hb56.DriverReservation.android.net.MyHttpHelper.doRequestForString (myhttphelper.java:103)
03-12 13:50:35.808:w/system.err (9801):At Com.hb56.DriverReservation.android.net.MyHttpHelper.doRequestForString (myhttphelper.java:72)
03-12 13:50:35.809:w/system.err (9801):At Com.hb56.driverreservation.android.loginactivity$myasynctaskreqkeyhttp.doinbackground (LoginActivity.java:283 )
03-12 13:50:35.810:w/system.err (9801):At Com.hb56.driverreservation.android.loginactivity$myasynctaskreqkeyhttp.doinbackground (LoginActivity.java:1)
03-12 13:50:35.812:w/system.err (9801):At Android.os.asynctask$2.call (asynctask.java:264)
03-12 13:50:35.813:w/system.err (9801):At Java.util.concurrent.futuretask$sync.innerrun (futuretask.java:305)
03-12 13:50:35.814:w/system.err (9801):At Java.util.concurrent.FutureTask.run (futuretask.java:137)
03-12 13:50:35.815:w/system.err (9801):At Android.os.asynctask$serialexecutor$1.run (asynctask.java:208)
03-12 13:50:35.816:w/system.err (9801):At Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1076)
03-12 13:50:35.817:w/system.err (9801):At Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:569)
03-12 13:50:35.819:w/system.err (9801):At Java.lang.Thread.run (thread.java:856)
03-12 13:50:35.821:w/system.err (9801): caused By:libcore.io.ErrnoException:recvfrom failed:econnreset (Connection Reset by Peer)
03-12 13:50:35.834:w/system.err (9801):At Libcore.io.Posix.recvfromBytes (Native Method)
03-12 13:50:35.835:w/system.err (9801):At Libcore.io.Posix.recvfrom (posix.java:131)
03-12 13:50:35.836:w/system.err (9801):At Libcore.io.BlockGuardOs.recvfrom (blockguardos.java:164)
03-12 13:50:35.838:w/system.err (9801):At Libcore.io.IoBridge.recvfrom (iobridge.java:545)
03-12 13:50:35.838:w/system.err (9801):... More
After writing a Java project, to call the server API, and log log logs, crawl packet file analysis, in the server's API, there is a filter to intercept the Access API, however, the code on the Android side exception is: HttpResponse HttpResponse = Httpclient.execute (request);//Pull Server link
Finally found that the problem is the Server API filter, not all the exception replenishment complete.
Android POST request exception via HTTP protocol (Connection reset by Peer)