"java.io.IOException:连接超时"与"java.io.IOException:连接超时"有什么区别?和"SocketTimeoutException:读取超时"; [英] What's the difference between "java.io.IOException: Connection timed out" and "SocketTimeoutException: Read timed out"

查看:2328
本文介绍了"java.io.IOException:连接超时"与"java.io.IOException:连接超时"有什么区别?和"SocketTimeoutException:读取超时";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我设置了一个套接字SoTimeout,然后从中读取.当读取时间超过超时限制时,我将收到"SocketTimeoutException:读取超时". 这是我的情况下的堆栈:

If I set a socket SoTimeout, and read from it. when read time exceed the timeout limit, I'll get an "SocketTimeoutException: Read timed out". and here is the stack in my case:

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)
    at org.apache.hadoop.ipc.Client$Connection$PingInputStream.read(Client.java:277)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
    at java.io.DataInputStream.readInt(DataInputStream.java:387)
    at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:527)
    at org.apache.hadoop.ipc.Client$Connection.run(Client.java:462)


但是在这里我遇到了"IOExcetion:连接超时",我不知道它是怎么发生的. 堆栈:


but here I encountered "IOExcetion: Connection timed out", i don't know how it happened. Stacks:

java.io.IOException: Connection timed out
    at sun.nio.ch.FileDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:198)
    at sun.nio.ch.IOUtil.read(IOUtil.java:171)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:245)
    at org.apache.hadoop.net.SocketInputStream$Reader.performIO(SocketInputStream.java:55)
    at org.apache.hadoop.net.SocketIOWithTimeout.doIO(SocketIOWithTimeout.java:142)
    at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:155)
    at org.apache.hadoop.net.SocketInputStream.read(SocketInputStream.java:128)
    at java.io.FilterInputStream.read(FilterInputStream.java:116)
    at org.apache.hadoop.ipc.Client$Connection$PingInputStream.read(Client.java:277)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    at java.io.DataInputStream.readInt(DataInputStream.java:370)
    at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:527)
    at org.apache.hadoop.ipc.Client$Connection.run(Client.java:462)

有人可以告诉我,这两个例外之间有什么区别,谢谢.

Can someone tell me what's the differences between the two exceptions, Thanks.

推荐答案

连接超时意味着您尝试连接到远程IP/端口对,但未成功:根本没有应答.在该阶段的另一个可能的错误是连接被拒绝,其中该对可用,但拒绝了您的连接尝试.这两个错误都出现在套接字的初始设置中.请注意,这些错误仅发生在TCP上,因为TCP连接需要建立会话.

A connection timeout means you attempted to connect to the remote IP/port pair and failed to do so: it did not answer at all. Another possible error at that stage would be connection refused, in which this pair is available but rejected your connection attempt. Both of these errors appear on the initial setup of a socket. Note that these errors only occur with TCP, since a TCP connection requires the establishment of a session.

当套接字读取超时时,表示您已连接,但无法及时读取数据.套接字上的超时是可配置的.您可能还会收到连接重置错误,这意味着您确实连接成功,但是另一端认为毕竟不值得:p

When you have a socket read timeout, it means you are connected, but failed to read data in time. Timeouts on sockets are configurable. You may also get a connection reset error, which means you did connect successfully, but the other end decided that after all you're not worth it :p

这篇关于"java.io.IOException:连接超时"与"java.io.IOException:连接超时"有什么区别?和"SocketTimeoutException:读取超时";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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