My client program connects to a server in the following manner in a procedure which is called upon user action (edit data, clicking a button):
if (not Net_Init) then
begin
Sock := fpSocket(AF_INET,SOCK_STREAM,0);
if (Sock = -1) then
begin
exit;
end;
Net_Init := true;
end;
if (not Connect(Sock,External_IP,Sin,Sout)) then
begin
exit;
end;
-- send data & get results...
close Sin, Sout
This works the first time, then fails with error "9" - bad file number.
Should I do the Connect inside the initialization IF? What if the connection times out while the user is editing his data?
Should I re-connect each time? Doesn't this waste time/resources?
Other? I see there are things like SO_KEEPALIVE = 9 and SO_LINGER = 13 but the fpc/rtl manual doesn't describe them.
I can hack up something that works, but I'm hoping for a tried and true solution.
Thanks.