Announcement

Collapse
No announcement yet.

Resuming a Large File Xfer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resuming a Large File Xfer

    In transfering a large file from a server to user, there is the potential for a connection snafu. If the user has been connected for 20mins with 3 mins left it can be super frustrating as we all know!

    I know some download tools can just resume where they left off. I assume they do this by comparing what is on the users hard drive against what is being sent, byte by byte, and then requesting the server to pick up at some specified byte?

    I would like to implement something like this, but using blocks of say 2k bytes. I suppose it would be possible to use an ACK for each block, but it seems like that might slow things down. Speed is important here.

    I suspect it would fairly easy to count "blocks" and send the server a request for the remaining blocks.

    Anyone confronted this before and used a better schema?

  • #2
    There's a nice DLL here: http://nsis.sourceforge.net/InetLoad with clean C source using the WinInet API, with resume capabilities. Would be simple to use the DLL, or follow their logic and rewrite in PB.
    --pdf

    Comment


    • #3
      >or follow their logic and rewrite in PB.
      Not that good with C im afraid

      Comment


      • #4
        Originally posted by Mike Trader View Post
        >or follow their logic and rewrite in PB.
        Not that good with C im afraid
        Trust me, it'll only hurt a little. The core is simply some if/thens around the WinInet functions, most significantly in this case InternetSetFilePointer()

        "||" = "OR"
        "==" = "="
        use "instr" vs "strncmp"
        *buf = LEFT$(buf, 1)

        Obviously there's more to it that this, but most of the code is callbacks for a GUI progress dialog.

        Code:
        resend:
                 if(req_sent_ok || HttpSendRequest(hFile, NULL, 0, post, post == NULL ? 0 : lstrlen(post)))
                 {
                    if(cnt == 0)
                    {
                       if(HttpQueryInfo(hFile, HTTP_QUERY_STATUS_CODE,
                          buf, &(rslt = sizeof(buf)), NULL))
                       {
                          if(strncmp(buf, "401", 3) == 0)
                             status = ERR_AUTH;
                          else if(strncmp(buf, "403", 3) == 0)
                             status = ERR_FORBIDDEN;
                          else if(strncmp(buf, "404", 3) == 0)
                             status = ERR_NOTFOUND;
                          else if(strncmp(buf, "407", 3) == 0)
                             status = ERR_PROXY;
                          else if(*buf == '4')
                             status = ERR_REQUEST;
                          else if(*buf == '5')
                             status = ERR_SERVER;
                       }
                       if(HttpQueryInfo(hFile, HTTP_QUERY_CONTENT_LENGTH, buf,
                                        &(rslt = sizeof(buf)), NULL))
                          fs = strtoul(buf, NULL, 0);
                       else fs = NOT_AVAILABLE;
                    }
                    else
                    {
                       if(!InternetSetFilePointer(hFile, cnt, NULL, FILE_BEGIN, 0))
                       {
                          status = ERR_REGET;
                       }
                    }
                 }
        --pdf

        Comment

        Working...
        X