Search code examples
delphiindydelphi-xe3

Resume EIdSocketError connection without restarting the download - Delphi


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;

Solution

  • 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