java.net.SocketException:连接重置 [英] java.net.SocketException: Connection reset

查看:97
本文介绍了java.net.SocketException:连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试从套接字读取时遇到以下错误.我正在该 InputStream 上执行 readInt(),但出现此错误.仔细阅读文档,这表明连接的客户端部分关闭了连接.在这个场景中,我是服务器.

I am getting the following error trying to read from a socket. I'm doing a readInt() on that InputStream, and I am getting this error. Perusing the documentation this suggests that the client part of the connection closed the connection. In this scenario, I am the server.

我可以访问客户端日志文件,但它没有关闭连接,实际上它的日志文件表明我正在关闭连接.那么有人知道为什么会这样吗?还要检查什么?当本地资源可能达到阈值时会出现这种情况吗?

I have access to the client log files and it is not closing the connection, and in fact its log files suggest I am closing the connection. So does anybody have an idea why this is happening? What else to check for? Does this arise when there are local resources that are perhaps reaching thresholds?

我注意到我有以下几行:

I do note that I have the following line:

socket.setSoTimeout(10000);

就在 readInt() 之前.这是有原因的(长话短说),但只是好奇,在什么情况下这可能会导致指示的错误?我的服务器在我的 IDE 中运行,我碰巧让我的 IDE 卡在断点上,然后我注意到完全相同的错误开始出现在我自己的 IDE 日志中.

just prior to the readInt(). There is a reason for this (long story), but just curious, are there circumstances under which this might lead to the indicated error? I have the server running in my IDE, and I happened to leave my IDE stuck on a breakpoint, and I then noticed the exact same errors begin appearing in my own logs in my IDE.

无论如何,只是提一下,希望不是红鲱鱼.:-(

Anyway, just mentioning it, hopefully not a red herring. :-(

推荐答案

有几个可能的原因.

  1. 另一端故意重置连接,我不会在这里记录的方式.应用软件这样做的情况很少见,而且通常是不正确的,但对于商业软件而言,这种情况并非不为人知.

  1. The other end has deliberately reset the connection, in a way which I will not document here. It is rare, and generally incorrect, for application software to do this, but it is not unknown for commercial software.

更常见的情况是,写入一个连接时,另一端已经正常关闭.换言之,应用协议错误.

More commonly, it is caused by writing to a connection that the other end has already closed normally. In other words an application protocol error.

当套接字接收缓冲区中有未读数据时关闭套接字也可能导致.

It can also be caused by closing a socket when there is unread data in the socket receive buffer.

在 Windows 中,软件导致连接中止"与连接重置"不同,是由您端发送的网络问题引起的.有一篇关于此的 Microsoft 知识库文章.

In Windows, 'software caused connection abort', which is not the same as 'connection reset', is caused by network problems sending from your end. There's a Microsoft knowledge base article about this.

这篇关于java.net.SocketException:连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆