Thanks Michael, I'll give it a try James -----Original Message----- From: fpc-pascal <fpc-pascal-boun...@lists.freepascal.org> On Behalf Of Michael Van Canneyt via fpc-pascal Sent: Sunday, September 6, 2020 11:12 AM To: James Richters <ja...@productionautomation.net>; FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org> Cc: Michael Van Canneyt <mich...@freepascal.org> Subject: Re: [fpc-pascal] Ethernet Relays
On Sun, 6 Sep 2020, James Richters via fpc-pascal wrote: > I've been using simpleget to control ethernet relays like this: > S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/30000/15'); > > But if the IP address does not exist on the network I get this error: > > An unhandled exception occurred at $0000000100032A4A: > ESocketError: Connection to 10.10.01.01:80 timed out. > > And my program terminates. Is there some way I can capture this error > with my program so I can just put up a message about the problem and > keep running? Yes, catch the ESocketError in a try..except: Try S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/30000/15'); except On E: ESocketError do Writeln('Could not connect to server'); end; > Is there a way to change the amount of time before the timeout? Yes, but then you need to create an instance, i.e. the Simple* commands won't do that for you: Instead, it will look like this: uses fphttpclient; Var C : TFPHTTPClient; begin C:=TFPHTTPClient.Create(Nil); try try C.ConnectTimeout:=10; // Or whatever you think is good C.Get('http://10.10.01.01/30000/15'); except On E: ESocketError do Writeln('Could not connect to server'); end; finally C.Free; end; end; Michael. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal