Android POST request exception via HTTP protocol (Connection reset by Peer)

Source: Internet
Author: User
Tags log log posix connection reset

last week, I met a Connection Reset by Peernetwork 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
The 1th exception is 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 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 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 (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 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): Failed:econnreset (Connection reset by Peer)
03-12 13:50:35.790:w/system.err (9801):At (
03-12 13:50:35.790:w/system.err (9801):At (
03-12 13:50:35.791:w/system.err (9801):At (
03-12 13:50:35.792:w/system.err (9801):At$000 (
03-12 13:50:35.793:w/system.err (9801):At$ (
03-12 13:50:35.794:w/system.err (9801):At (
03-12 13:50:35.795:w/system.err (9801):At (
03-12 13:50:35.796:w/system.err (9801):At Org.apache.http.impl.conn.DefaultResponseParser.parseHead (
03-12 13:50:35.797:w/system.err (9801):At (
03-12 13:50:35.798:w/system.err (9801):At Org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader ( : 180)
03-12 13:50:35.799:w/system.err (9801):At Org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader (
03-12 13:50:35.800:w/system.err (9801):At Org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader ( )
03-12 13:50:35.801:w/system.err (9801):At Org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse (
03-12 13:50:35.802:w/system.err (9801):At Org.apache.http.protocol.HttpRequestExecutor.execute (
03-12 13:50:35.803:w/system.err (9801):At Org.apache.http.impl.client.DefaultRequestDirector.execute (
03-12 13:50:35.804:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (
03-12 13:50:35.805:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (
03-12 13:50:35.806:w/system.err (9801):At Org.apache.http.impl.client.AbstractHttpClient.execute (
03-12 13:50:35.806:w/system.err (9801):At (
03-12 13:50:35.807:w/system.err (9801):At (
03-12 13:50:35.808:w/system.err (9801):At (
03-12 13:50:35.809:w/system.err (9801):At$myasynctaskreqkeyhttp.doinbackground ( )
03-12 13:50:35.810:w/system.err (9801):At$myasynctaskreqkeyhttp.doinbackground (
03-12 13:50:35.812:w/system.err (9801):At Android.os.asynctask$ (
03-12 13:50:35.813:w/system.err (9801):At Java.util.concurrent.futuretask$sync.innerrun (
03-12 13:50:35.814:w/system.err (9801):At (
03-12 13:50:35.815:w/system.err (9801):At Android.os.asynctask$serialexecutor$ (
03-12 13:50:35.816:w/system.err (9801):At Java.util.concurrent.ThreadPoolExecutor.runWorker (
03-12 13:50:35.817:w/system.err (9801):At Java.util.concurrent.threadpoolexecutor$ (
03-12 13:50:35.819:w/system.err (9801):At (
03-12 13:50:35.821:w/system.err (9801): caused failed:econnreset (Connection Reset by Peer)
03-12 13:50:35.834:w/system.err (9801):At (Native Method)
03-12 13:50:35.835:w/system.err (9801):At (
03-12 13:50:35.836:w/system.err (9801):At (
03-12 13:50:35.838:w/system.err (9801):At (
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)

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: 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.