ConnectionTimeout对了socketTimeout对了、ConnectionTimeout、socketTimeout

2023-09-13 02:26:47 作者:国民岳父

林具有我使用的是库的问题,它可能是图书馆,也可能是我使用它错了!

Im having a problem with a library I am using, it might be the library or it might be me using it wrong!

基本上,当我这样做(超时毫秒)

Basically when I do this (Timeout in milliseconds)

_ignitedHttp.setConnectionTimeout(1);  // v short
_ignitedHttp.setSocketTimeout(60000);  // 60 seconds

没有超时异常产生的工程确定,但是,当我做到这一点:

No timeout exception is generated works ok, however, when I do this:

_ignitedHttp.setConnectionTimeout(60000);  // 60 seconds
_ignitedHttp.setSocketTimeout(1);          // v short

我得到一个Socket异常。

I get a Socket Exception.

所以我的问题是,为什么我不能模拟连接异常?我误解插座和连接超时之间的区别?图书馆是这里(尚未正式realsed)。

So my question is why can I not simulate a Connection Exception? Am I misunderstanding the difference between a socket and a connection time-out? The library is here (not officially realsed yet).

推荐答案

A 连接超时只发生在启动TCP连接。这种情况经常发生,如果远程计算机没有应答。这意味着服务器已关闭,您使用了错误的IP / DNS名称或网络连接到服务器已关闭。

A connection timeout occurs only upon starting the TCP connection. This usually happens if the remote machine does not answer. This means that the server has been shut down, you used the wrong IP/DNS name or the network connection to the server is down.

A 套​​接字超时是专用于监控的不断传入的数据流。如果数据流在指定超时中断连接被视为停滞/断。当然,这仅适用于其中数据接收所有的时间连接。

A socket timeout is dedicated to monitor the continuous incoming data flow. If the data flow is interrupted for the specified timeout the connection is regarded as stalled/broken. Of course this only works with connections where data is received all the time.

通过套接字超时设置为1,这将需要在收到每毫秒的新数据(假设您阅读数据块明智和块足够大)!

By setting socket timeout to 1 this would require that every millisecond new data is received (assuming that you read the data block wise and the block is large enough)!

如果只输​​入流摊位超过一毫秒,你正在运行到一个暂停。

If only the incoming stream stalls for more than a millisecond you are running into a timeout.