Topic: Socket Error # 10054 Connection reset by peer.

When getting the HTML Contents from an URL using HTTPGet I'm getting the following error message "Socket Error # 10054 Connection reset by peer" only when the application has been idle for a while.  If I'm constantly using the application the error does not show up, it only shows when the application has not been use for a while.

Below is a sample code I use and  even if I use the TRY and EXCEPT the error message shows up. Any Ideas how to troubleshoot this issue.  Is there a HTTPGet.Free  option to free the TCP connection.

 
   url:=frm_main.Edit1.Text;

     try
         get_url:= HTTPGet(url);
         frm_main.Memo1.Text:= get_url;
    except
        if ExceptionMessage <> 'Socket Error # 10054' then  frm_main.Memo1.Lines.Add('Unknown Error') else frm_main.Memo1.Lines.Add(ExceptionMessage);
    end;
Post's attachments

Attachment icon get_html.zip 325.14 kb, 443 downloads since 2018-03-29 

2 (edited by mathmathou 2018-03-30 04:59:09)

Re: Socket Error # 10054 Connection reset by peer.

Hello livexox,


If you want to intercept the exception, I think you need to add the "True" flag at the end of your HTTPGet instruction, like this :

procedure Get_content (Sender: string; var Cancel: boolean);
begin
     url:=frm_main.Edit1.Text;

     try
         get_url:= HTTPGet(url,True);
         frm_main.Memo1.Text:= get_url;
    except
        if ExceptionMessage <> 'Socket Error # 10054' then  frm_main.Memo1.Lines.Add('Unknown Error') else frm_main.Memo1.Lines.Add(ExceptionMessage);
    end;

No need to free the HTTP con, I think Dmitry frees it on Form close.


As for the inactivity delay, unfortunately I have no clue...


Wish you a good week-end


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

3 (edited by livexox 2018-03-30 05:53:39)

Re: Socket Error # 10054 Connection reset by peer.

Thanks for you help mathmathou. I wish there will be a way to manually close the HTTPGet connection because in some instances you need to leave the application open for long times. I also notice that this happens more frequently when I'm getting the content from the local network/Intranets.  Anyways after a few hours of research I found a solution.  This works for me and now I can leave the application open for a long time and when I need to connect again to the URL I no longer get the error message. Hope this helps someone else.

procedure get_html(Sender: string; var Cancel: boolean);
var http: variant;
begin
     try
         http:=createoleobject('WinHttp.WinHttpRequest.5.1');
         http.open('GET', frm_main.Edit1.Text , false);
         http.send;
         frm_main.Memo1.Text:= http.responsetext;
    finally
         http:= nil;
    end;

end;
Post's attachments

Attachment icon get_html.zip 336.19 kb, 413 downloads since 2018-03-30