During the socket programming process, the client sends a request to the server and encounters the following error: Java.net.SocketException:recvfrom failed:econnreset (Connection reset by Peer)
01-11 23:07:25.065:w/system.err (11804): Java.net.SocketException:recvfrom failed:econnreset (Connection reset by peer )
01-11 23:07:25.073:w/system.err (11804): at Libcore.io.IoBridge.maybeThrowAfterRecvfrom (Iobridge.java : 634)
01-11 23:07:25.073:w/system.err (11804): at libcore.io.IoBridge.recvfrom (iobridge.java:596)
01-11 23:07:25.073:w/system.err (11804): at java.net.PlainSocketImpl.read (plainsocketimpl.java:492)
01-11 23:07:25.073:w/system.err (11804): at java.net.plainsocketimpl.access$000 (plainsocketimpl.java:42)
01-11 23:07:25.073:w/system.err (11804): at Java.net.plainsocketimpl$plainsocketinputstream.read ( plainsocketimpl.java:242)
01-11 23:07:25.073:w/system.err (11804): at Java.io.BufferedInputStream.read ( bufferedinputstream.java:290)
01-11 23:07:25.073:w/system.err (11804): at Com.emp.common.pos.JConnection.read (jconnection.java:185)
Debugging this error, the most annoying is the two sides, find the root cause of the problem, the client said server processing problems, the server said the client code is wrong.
Client clearly access to other channels is no problem, why access to the channel will be an error. Then the server has not received the request. First, analyze the wrong translations:
Connection Reset by Peer: The connection is side equal. So what does peer mean. There is this passage:
The client is the originator of the communication, and the server program passively waits for the client to initiate the communication and respond to it.
Whether a program is a client or a server determines the socket APIs that it uses to establish communications with its peers (peer) (the client's peer is the server and vice versa).
It is clear that the following conclusions have been drawn:
1, the client's peer is the server, the server peer is the client;
2, the client access to other channels before the normal communication, indicating that the client code error probability is not high, the server to deal with the suspected sudden rise;
3, the server reset the connection. At the very least, the server received the request message, because for some reason the processing data failed, forced to reset the connection.
Finally, after the investigation and confirmation, it confirms our conclusion, the server in processing message length error. The two sides coordinate the correction, finally the communication succeeded.