java.net.SocketTimeoutException:读取超时的原因是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19379426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the cause for java.net.SocketTimeoutException: Read timed out
提问by Madhu Sudhan Reddy
I have written a java code to connect FTP.I used ftp4j-1.7.2
jar to connect FTP through java.I have used String[] "it.sauronsoftware.ftp4j.FTPClient.connect(String arg0)" and "it.sauronsoftware.ftp4j.FTPClient.disconnect(boolean arg0)" methods to connect and disconnect from FTP.The code is working fine when i run it in java 1.5 but it's throwing "java.net.SocketTimeoutException: Read timed out" while disconnecting when i run it in java 1.6.Can anyone please let me know solution for this.
我写了一个java代码来连接ftp4j-1.7.2
FTP。我用jar通过java连接FTP。我用过String[]“ it.sauronsoftware.ftp4j.FTPClient.connect(String arg0)”和“ it.sauronsoftware.ftp4j.FTPClient”。 disconnect(boolean arg0)" 连接和断开 FTP 的方法。当我在 java 1.5 中运行它时,代码工作正常,但是当我在 java 1.6 中运行它时,它在断开连接时抛出“ java.net.SocketTimeoutException: Read timed out”。任何人都可以让我知道解决方案。
Error Log:
错误日志:
Stack:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:107)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:93)
at java.io.InputStreamReader.read(InputStreamReader.java:151)
at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
at it.sauronsoftware.ftp4j.FTPClient.disconnect(FTPClient.java:1133)
回答by Roger
This could be an IPv issue. Try this flag:
这可能是 IPv 问题。试试这个标志:
-Djava.net.preferIPv4Stack=true
回答by user207421
It means no data arrived during the timeout period. In this case no reply to the disconnect request. Clearly the library you are using is setting a read timeout, or maybe you are, and it is too short, see if you can increase it.
这意味着在超时期间没有数据到达。在这种情况下,没有对断开连接请求的答复。很明显你用的库设置了读取超时,或者你是,而且太短了,看看能不能增加。
I can't account for the different behaviour with different JDKs, unless there was a read timeout fix somewhere, but I've never been aware of any read timeout problems at all, and I go all the way back to 1.1.2.
我无法解释不同 JDK 的不同行为,除非某处有读取超时修复,但我从来没有意识到任何读取超时问题,我一直回到 1.1.2。