我们的项目实现了自己的长连接框架,基于NIO为推送,它过去的工作正常。最近,出现了一些问题,"SocketChannel.read(byteBuffer)“抛出异常"java.net.SocketException: recvfrom failed: ECONNRESET (Connection by peer)",详细信息如下:

图像包含错误消息
错误代码如下所示:
private void read(ByteBuffer byteBuffer, int length) throws Exception {
int count = 0;
long readBeginMills = SystemClock.elapsedRealtime();
while (count < length) {
try {
int readCount = mSocketChannel.read(byteBuffer);
long nowMills = SystemClock.elapsedRealtime();
if (readCount > 0) {
count += readCount;
readBeginMills = nowMills;
}
//1.readCount为-1时是连接断开了,直接报错重连
//2.如果读取数据超过了20s也报错重连
if(nowMills - readBeginMills >= 20000 || readCount == -1){
throw new LostTcpByteException("byte lost exception,need to shutdown and reconnection");
}
} catch (Exception e) {
throw e;
}
}
}我找了很多类似的错误,但找不到解决问题的好主意,我该怎么办?谢谢你的任何一位专家!
发布于 2017-05-17 07:33:33
以下任一项:
https://stackoverflow.com/questions/44017634
复制相似问题