[fpc-pascal] FPConnect Timeout
James Richters
james.richters at productionautomation.net
Wed Jun 8 20:07:17 CEST 2022
I'm not quite following how I could implement that.
Here is what I am trying to do:
Uses
Serial,Sysutils,Sockets,CRT;
var
Socket_Address: TSockAddr;
opt: LongWord;
Connect_Result : Integer;
TCP_Connect_Socket : Tsocket;
begin
Modbus.Device[Device_Number].TCP_Socket := fpsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if Modbus.Device[Device_Number].TCP_Socket = TSocket(INVALID_SOCKET) then
Writeln('Error Creating Socket: ',SocketError);
Socket_Address.sin_family := AF_INET;
Socket_Address.sin_addr := StrToNetAddr(Modbus.Device[Device_Number].Connection);
Socket_Address.sin_port := htons(Modbus.Device[Device_Number].TCP_Port);
Connect_Result := fpconnect(Modbus.Device[Device_Number].TCP_Socket, @Socket_Address, sizeof(Socket_Address));
if Connect_Result = SOCKET_ERROR then
Writeln('Error Connecting Socket: ',SocketError); // I want to get this error in 2 seconds
...
Are you saying to use TInetSocket instead of the Sockets unit? Or do I just figure out how to use set ConnectTimeout and then that's the timeout that will be used, and still use everything else the same?
James
-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Dimitrios Chr. Ioannidis via fpc-pascal
Sent: Wednesday, June 8, 2022 1:11 PM
To: fpc-pascal at lists.freepascal.org
Cc: Dimitrios Chr. Ioannidis <d.ioannidis at nephelae.eu>
Subject: Re: [fpc-pascal] FPConnect Timeout
Hi,
Στις 8/6/2022 7:27 μ.μ., ο/η James Richters via fpc-pascal έγραψε:
> Is there any way to specify a shorter timeout for FPConnect?
AFAIK, socket connect timeout is implemented in ssockets ( in TSocketStream ) not in sockets unit.
You can use the TInetSocket's class from ssockets unit ( this is what fphttpclient uses ) overloaded constructor with the aConnectTimeout parameter or if you want you can use the ConnectTimeout property before connect and you're ready to go ...
regards,
--
Dimitrios Chr. Ioannidis
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list