Question

Good day ...

I download a program which generates the error Socket'm using except on E: EIdSocketError the begin ... He shows me the error that is generated ... But I would like to address this error ... Because it disconnects with the site I'm downloading, and he for the program, I can not return any download ... unless you close the program and reopen ...

How can I be getting this error, make him try reset a new connection to the site, without me having to restart the program ... So I go back download the latest downloaded file .... because with socket error have to restart the program and return to download the Zero ... 1mb files are small, but they are around 200 for download:

on E: EIdSocketError do begin
                     ShowMessage('Socket 2');

                     // +++++------
                     FreeAndNil(fileDownload);
                     fileDownload := TFileStream.Create(local_exe+'media_'+IntToStr(down_num)+'.mp4', fmCreate);
                     IdHTTP.Get(montarURL, fileDownload);
                     Memo1.Lines.Add(formatdatetime('dd/mm/yyyy',now)+' '+formatdatetime ('hh:mm:ss',now)+' Lista '+IntToStr(numero_tentativa_loop_um)+'. Connection restored.');
                 end;
Was it helpful?

Solution 2

The Socket Error # 10054 has to correct, because he was the one who appeared ... I do not know if it will work with others:

RemoveComponent(IdHTTP);
IdHTTP.Free;
IdHTTP := Nil;
IdHTTP := TIdHTTP.Create(Self);

ATT MT

OTHER TIPS

EIdSocketError means exactly what its name says - a socket error occurred. Without seeing the actual socket error code involved, typically all you can do to recovery is just Disconnect() the socket, Clear the IOHandler.InputBuffer, and re-Connect() and resume your download where you left off (if possible) or re-start the download from the beginning again.

For HTTP, you can resume a download if the resource being downloaded accepts a Range: bytes=... request header (see the TIdHTTP.Request.Range property), such as if it reported an Accept-Ranges: bytes response header (see the TIdHTTP.Response.AcceptRanges property) in an earlier download attempt. See RFC 2616 Section 14.35 for more details.

Update: For example:

try
  IdHTTP.Get(montarURL, fileDownload);
except
  on E: EIdSocketError do begin
    IdHTTP.Disconnect;
    if IdHTTP.IOHandler <> nil then IdHTTP.IOHandler.InputBuffer.Clear;
    ...
    if IdHTTP.Response.AcceptRanges = 'bytes' then begin
      IdHTTP.Request.Range := IntToStr(fileDownload.Size) + '-';
    end else begin
      fileDownload.Size := 0;
    end;
    IdHTTP.Get(montarURL, fileDownload);
    ...
  end;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top