Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

java - java.net.SocketException:连接重置(java.net.SocketException: Connection reset)

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.

(我正在该InputStream上执行readInt() ,并且遇到此错误。)

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);

just prior to the readInt() .

(就在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.

(我的服务器在IDE中运行,我碰巧将IDE卡在断点上,然后我发现完全相同的错误开始出现在我自己的IDE日志中。)

Anyway, just mentioning it, hopefully not a red herring.

(无论如何,仅提及它,希望它不会成为鲱鱼。)

:-(

(:-()

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are several possible causes.

(有几种可能的原因。)

  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.

    (应用程序软件很少会这样做,而且通常是不正确的,但对于商业软件而言却并非未知。)

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

    (换句话说,应用程序协议错误。)

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

    (当套接字接收缓冲区中有未读数据时,关闭套接字也会导致此错误。)

  4. In Windows, 'software caused connection abort', which is not the same as 'connection reset', is caused by network problems sending from your end.

    (在Windows中,“软件引起的连接中止”与“连接重置”不同,这是由您的终端发送的网络问题引起的。)

    There's a Microsoft knowledge base article about this.

    (有关于此的Microsoft知识库文章。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...