套接字读取超时-我应该去0(inifite) [英] socket read timed out - should I go for 0 (inifite)

查看:369
本文介绍了套接字读取超时-我应该去0(inifite)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在下载一个大文件(例如大约100mb),并且不时收到SocketException: Read timed out.

I'm downloading a big file (say around 100mb) and I'm receiving SocketException: Read timed out every now and then.

我正在考虑提高套接字超时.实际上,我正在考虑将套接字超时设置为0(无穷大),因为最终我的应用程序将下载的文件的大小甚至可能大于300mb,甚至大于300mb.这是一个好习惯吗?

I'm thinking of raising the socket timeout. Actually, I'm thinking of setting the socket timeout to 0 (infinite) as eventually the sizes that the files that my app will be downloading may even go greater than 300mb, or even greater than 300mb. Is this a good practice?

关于套接字超时,超时倒计时实际上何时开始?我的意思是,当发生套接字超时时,是否表示连接仍然​​有效并且文件仍在继续下载,而只是由于配置了套接字超时而导致超时?或者,当倒计时显示连接仍然​​有效但服务器未发送任何数据时,倒计时是否开始?倒计时开始并达到超时了?

Regarding socket timeout, when does the timeout countdown actually starts? I mean, when a socket timeout occurs, does it mean that the connection is still alive and file is still continously being downloaded but just timeouts because a socket timeout is configured? Or does the countdown starts when it figures that connection is still alive but no data is being sent by the server; thus countdown begins and reached the timeout?

因为情况是后者,所以我不会选择使用无限,因为这是由服务器未向我发送数据而不是由我的应用程序引起的.

Because if the case is the latter, then I'll not opting to go to infinite, since it will be caused by the server not sending me data and not by my app.

推荐答案

我正在下载一个大文件(例如100mb左右),并且收到SocketException:读取时不时地超时.

I'm downloading a big file (say around 100mb) and I'm receiving SocketException: Read timed out every now and then.

因此,您的读取超时时间太短,或者对等节点的响应能力不足,无法满足您的需求.

So your read timeout is too short, or the peer isn't responsive enough for your needs.

我正在考虑提高套接字超时.

I'm thinking of raising the socket timeout.

从哪里来?

实际上,我正在考虑将套接字超时设置为0(无穷大),因为最终我的应用程序将下载的文件的大小甚至可能大于300mb,甚至大于300mb.这是一个好习惯吗?

Actually, I'm thinking of setting the socket timeout to 0 (infinite) as eventually the sizes that the files that my app will be downloading may even go greater than 300mb, or even greater than 300mb. Is this a good practice?

读取超时与下载大小无关.它与请求的预期服务时间有关.我通常建议将其设置为预期服务时间的两倍.毕竟,读取超时的目的是告诉您对等方何时没有响应.

The read timeout has nothing whatsoever to do with the download size. It has to do with the expected service time of a request. I generally recommend setting it to double the expected service time. The purpose of a read timeout is to tell you when the peer isn't responding, after all.

关于套接字超时,超时倒计时实际上何时开始?

Regarding socket timeout, when does the timeout countdown actually starts?

当您输入读取方法时.

我的意思是,当套接字超时发生时,是否表示该连接仍处于活动状态

I mean, when a socket timeout occurs, does it mean that the connection is still alive

是的

文件仍在不断下载

and file is still continously being downloaded

不.在超时时间内没有数据到达.

No. No data has arrived within the timeout period.

但是只是超时,因为已配置了套接字超时?

but just timeouts because a socket timeout is configured?

读取超时,因为(a)设置了读取超时,并且(b)到期.不要想太多.

The read times out because (a) you set a read timeout and (b) it expired. Don't overthink this.

或者当倒计时显示连接仍然​​有效但服务器未发送任何数据时,倒计时是否开始?倒计时开始并达到超时了?

Or does the countdown starts when it figures that connection is still alive but no data is being sent by the server; thus countdown begins and reached the timeout?

请参阅上文.

因为情况是后者,所以我不会选择使用无限,因为这是由服务器未向我发送数据而不是由我的应用程序引起的.

Because if the case is the latter, then I'll not opting to go to infinite, since it will be caused by the server not sending me data and not by my app.

读取超时是由于数据在接收应用程序配置的超时时间内未到达而引起的.超时时间可能太短,这是应用程序的错误,也可能是因为对等方未发送任何东西(这是对等方的错误),或两者都有.无法确定先验

The read timeout is caused by data not arriving within the timeout period configured by the receiving application. The timeout could be too short, which is the application's fault, or it could be because the peer didn't send anything, which is the peer's fault, or both. It isn't possible to decide a priori.

这篇关于套接字读取超时-我应该去0(inifite)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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