Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

HTTPClient Timeout Just delays the connection execution

I have been using the Ti.Network.HTTPClinet in an iPhone app and it seems that when I use setTimeout(5000) it will delay the post from hitting the server for 5 seconds. Is this how the timeout should be working? It seems to be more of a delay then a timeout setting.

Thanks

— asked November 17th 2010 by Thomas Wheeler
  • httpclient
  • iphone
  • mobile
0 Comments

2 Answers

  • Thomas

    Yes, setTimeout executes a code snippet or a function after specified delay. Hence, what you are observing is expected behaviour.

    I think what you are really looking for is setInterval:

    setInterval takes 2 arguments: function and timeout in milliseconds
    for how often the function should be executed until cancelled and
    returns a timer handle that can be used to cancel a timer with
    clearInterval.
    

    See Titanium's built-in timers for this extract.

    — answered November 17th 2010 by Paul Dowsett
    permalink
    2 Comments
    • Thanks for the response Hal. I understand the setTimeout / setIntraval functions. I am actually referring to the HTTPClient setTimeout as outlined in the
      Mobile API Docs.

      — commented November 17th 2010 by Thomas Wheeler
    • Oh, I stand corrected, Thomas. :) In that case, it does indeed seem strange behaviour, and I cannot imagine the reason. I agree with you, I too would expect it to wait for a response within 5 seconds, and cancel the request when the period ends. Hopefully someone will chime in with an explanation.

      — commented November 17th 2010 by Paul Dowsett
  • Thanks for the response Hal. I understand the setTimeout / setIntraval functions. I am actually referring to the HTTPClient setTimeout as outlined in the
    Mobile API Docs.

    — answered November 17th 2010 by Thomas Wheeler
    permalink
    1 Comment
    • Oh, I stand corrected, Thomas. :) In that case, it does indeed seem strange behaviour, and I cannot imagine the reason. I agree with you, I too would expect it to wait for a response within 5 seconds, and cancel the request when the period ends. Hopefully someone will chime in with an explanation.

      — commented November 17th 2010 by Paul Dowsett
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.