HttpURLConnection setConnectTimeout() has no effect

前端 未结 8 1530
刺人心
刺人心 2020-12-04 21:40

I\'m connecting to a simple RSS feed using HTTPUrlConnection. It works perfectly. I\'d like to add a timeout to the connection since I don\'t want my app hanging in the even

8条回答
  •  天命终不由人
    2020-12-04 22:16

    I was facing the same issue. Setting the connectionTimeout and readTimeout does not seems to return the exception as expected, but take really. It took me while to check the URLConnection() Method and understand what is going on. In the documentation for setConnectTimeout there is a warning

    "if the hostname resolves to multiple IP addresses, this client will try each. If connecting to each of these addresses fails, multiple timeouts will elapse before the connect attempt throws an exception." This mean s if you have 10 ips resolved by your host your actual time out will "10*readTimeoutSet".

    You can check ips for the the host name here

提交回复
热议问题