0

I've got some trouble downloading a webpage's HTML (see this question: Android: Downloading HTML not always working).

In my code, I use this method:

HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);

I'm not really sure what it means. Does this mean that if it takes longer than 3000 millis to download the HTML file (for which I use it), it stops? Or does it mean something else?

Also, what it the difference between that method and setSoTimeout?

Community
  • 1
  • 1
Xander
  • 5,487
  • 14
  • 49
  • 77

1 Answers1

7

It means that if you haven't made a connection in 3000 ms, it will stop trying.

The setSoTimeout() method is essentially the same thing, but it will wait for more than just the initial connection. So you would be checking each packet to see if it timed out, while the setConnectionTimeout() method will only time out on the initial connection. See this answer for more details.

Community
  • 1
  • 1
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
  • So it can't be that on a slow 3g connection, it takes really long (more than 3000 ms) to make a connection and that that's why I'm getting 0 as the Status Code? – Xander Nov 25 '12 at 11:22
  • It could mean something else is going on as well. Make sure that the URL you are attempting to connect to is valid first. Also, if you want to be really sure that it isn't the amount of time, setting it to 0 will tell the connection not to time out at all. – PearsonArtPhoto Nov 25 '12 at 11:25
  • It can also happen on WiFi, why not 3g? Server not responding, hickup with router, etc. – RvdK Nov 25 '12 at 11:26
  • @PoweRoy I think your understanding me wrong. My code (see this question: http://stackoverflow.com/questions/13550161/android-downloading-html-not-always-working) is not always working on a slow 3g connection (returning Status Code = 0). And I wondered if it could have got something to do with the timeout. – Xander Nov 25 '12 at 11:29
  • @PearsonArtPhoto I'm pretty sure my URL is correct. Have you maybe got an idea why it is going well with a fast internet connection (wifi and sometimes 3g) and not on a slow internet connection (for example slow 3g)? – Xander Nov 25 '12 at 11:35