Keyword: recv failed
Java.net. SocketException: Software caused connection abort: recv failed
At java.net. SocketInputStream. socketRead0 (Native Method)
At java.net. SocketInputStream. read (fig. java: 129)
At java.net. SocketInputStream. read (fig. java: 182)
Clients <--> servers communicate with each other through a persistent socket connection. The client has a receiving thread in the while (true ){..} the client continuously reads data from the InputStream stream. The client sends a heartbeat packet every several seconds. If the number of consecutive heartbeat packets has reached the specified number, the client considers the link to be abnormal, close the socket, the server will throw java.net. socketException: Connection reset by peer is abnormal, and then the thread allocated to this socket Connection exits, then the client is in the while (true ){..} loop. when reading the stream, the java.net will be sent. socketException:
Software caused connection abort: recv failed exception.
Try {
String host = getCodeBase (). getHost ();
Byte [] response = new byte [50500];
Host = "192.168.2.148 ";
ClientSocket = new Socket (host, 16555 );
// The input and output streams are required.
Outbound = new DataOutputStream (clientSocket. getOutputStream ());
Inbound = new DataInputStream (clientSocket. getInputStream ());
// Send a request to the server
Ps = new PrintStream (outbound );
Byte [] cmd = new byte [1, 1024];
Cmd [0] = 0x7e;
Cmd [1] = 0x00;
Ps. write (cmd,); // The first sending
Ps. flush ();
Inbound. Read (response, 0, 50500); // No exception is reported here
CMD [0] = 0x7e;
CMD [1] = 0x01;
PS. Write (CMD,); // The second sending
PS. Flush ();
If (inbound. Read (response, 0, 50500) =-1) // an exception is reported here
Return false;
Return true;
}
Catch (ioexception IOE ){
System. Out. println ("ioexception:" + IOE );
Return false;
}