ConnectionTimeout 与 SocketTimeout [英] ConnectionTimeout versus SocketTimeout

查看:38
本文介绍了ConnectionTimeout 与 SocketTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having a problem with a library that 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 and it works ok, however, when I do the following,

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

我收到一个套接字异常.

I get a Socket Exception.

那么,我的问题是为什么我不能模拟连接异常?我误解了套接字和连接超时之间的区别吗?该库位于这里(尚未正式发布).

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 released yet).

推荐答案

连接超时仅在启动 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, wrong port or the network connection to the server is down.

套接字超时专用于监控连续传入的数据流.如果数据流在指定的超时时间内中断,则连接被视为停止/中断.当然,这只适用于一直接收数据的连接.

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.

这篇关于ConnectionTimeout 与 SocketTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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