Archived Forum Post

Index of archived forum posts

Question:

HTTP ReadTimeout does not work?

Sep 11 '12 at 22:23
static void Main(string[] args)
        {
            var http = new Http();
            var success = http.UnlockComponent("Anything for 30-day trial");
            if (success != true)
            {
                Console.WriteLine(http.LastErrorText);
            }
            http.ConnectTimeout = 2;
            http.ReadTimeout = 2;
            success = http.Download("http://www.python.org/ftp/python/2.5/python-2.5.msi", "python-2.5.msi");
            if (success != true)
                Console.WriteLine(http.LastErrorText);
            else
                Console.WriteLine("Done");
        }

After 2 seconds, program still running. Can you fix it?


Answer

Use the AbortCheck event. See this: http://www.cknotes.com/?p=149


Answer

ReadTimeout is the amount of time in seconds to wait before timing out when reading from an HTTP server. The ReadTimeout is the amount of time that needs to elapse while no additional data is forthcoming. During a long download, if the data stream halts for more than this amount, it will timeout. Otherwise, there is no limit on the length of time for the entire download.


Answer

But ConnectTimeout didn't work. How to stop it after 2 seconds?


Answer

Please provide the contents of the LastErrorText.


Answer

ChilkatLog:
  Download:
    DllDate: Aug  5 2012
    UnlockPrefix: Anything for 30-day trial
    Username: THUONGTIN:Tin
    Architecture: Little Endian; 32-bit
    Language: .NET 4.0
    VerboseLogging: 0
    hcCurDate: Tue, 11 Sep 2012 21:42:34 +0700
    hcExpire: 7/2012
    backgroundThread: 0
    url: http://www.python.org/ftp/python/2.5/python-2.5.msi
    toLocalPath: python-2.5.msi
    localFileAlreadyExists: 1
    QuickGetToOutput_Download:
      qGet_1:
        simpleHttpRequest_3:
          httpMethod: GET
          requestUrl: http://www.python.org/ftp/python/2.5/python-2.5.msi
          Connecting to web server...
          httpServer: www.python.org
          port: 80
          ConnectTimeoutMs_1: 2000
          calling ConnectSocket2
          IPV6 enabled connect with NO heartbeat.
          connectingTo: www.python.org
          dnsCacheLookup: www.python.org
          Resolving domain name (IPV4)
          GetHostByNameHB_ipv4: Elapsed time: 15 millisec
          myIP_1: 192.168.1.65
          myPort_1: 6714
          connect successful (1)
          connectElapsedMs: 359
          -- BuildGetRequest --
          Not auto-adding cookies.
          sendElapsedMs: 0
          StatusCode: 200
          StatusText: OK
          Reading response body...
          readResponseElapsedMs: 28563
        --simpleHttpRequest_3
      --qGet_1
    --QuickGetToOutput_Download
    DownloadNumBytes: 10695680
    bFileDeleted: 0
    totalElapsedMs: 28922
    ContentLength: 10695680
    Success.
  --Download
--ChilkatLog

Answer

ConnectTimeoutMs_1: 2000 totalElapsedMs: 28922


Answer

Correct. Did you understand this?

ReadTimeout is the amount of time in seconds to wait before timing out when reading from an HTTP server. The ReadTimeout is the amount of time that needs to elapse while no additional data is forthcoming. During a long download, if the data stream halts for more than this amount, it will timeout. Otherwise, there is no limit on the length of time for the entire download.

The ReadTimeout dosn't put a limit on the total download time -- it limits the amount of time when your download gets "stuck", i.e. stops mid-way and for some reason no more data is arriving.


Answer

I want to stop download after 2 seconds. How can do it?


Answer

static void Main(string[] args)
    {
        bool abort = false;
        var http = new Http();
        var success = http.UnlockComponent("Anything for 30-day trial");
        if (success != true)
        {
            Console.WriteLine(http.LastErrorText);
        }

        http.EnableEvents = true;
        http.HeartbeatMs = 200;
        http.OnAbortCheck += (sender, e) =>
        {
            if (abort)
                e.Abort = true;
        };

        new Thread(() =>
        {
            Thread.Sleep(2000);
            abort = true;
        }).Start();

        success = http.Download("http://www.python.org/ftp/python/2.5/python-2.5.msi", "python-2.5.msi");
        if (success != true)
            Console.WriteLine(http.LastErrorText);
        else
        {
            Console.WriteLine("Done");
        }
    }