Il 23/07/2012 14.18, Lukas Gebauer ha scritto:
Hi, I'm Denis from Italy. Thanks for your great work!
>I have implemented TTCPBlockSocket, how can I detect client
>disconnection? Can I use keep alive?
http://synapse.ararat.cz/doku.php/public:howto:activeconnection



MMM..

I have tried this solution but does not work if the remote host closes the connection brutally, like the wire unplugged. These two functions (for enable keep alive) work correctly on Windows Xp. Can somebody test these functions on Vista or Seven?

            SetKeepAliveStatus(ClientSocket, 1);
            SetKeepAliveValue(ClientSocket, 1, 500, 500);


*function SetKeepAliveStatus(Socket: NativeInt; OptVal: Integer): Boolean;*
begin
  SetKeepAliveStatus:= false;
if SetSockOpt(Socket, SOL_SOCKET, SO_KEEPALIVE, @OptVal, SizeOf(OptVal))= 0 then SetKeepAliveStatus:= true;
end;

*function SetKeepAliveValue(Socket: NativeInt; OnOff, Time, Interval: Integer): Boolean*;
const
  SIO_KEEPALIVE_VALS= IOC_IN or IOC_VENDOR or 4;
type TTcpKeepAlive= packed record
  OnOff, KeepAliveTime, KeepAliveInterval: u_long;
end;
var
  KeepAliveIn: TTcpKeepAlive;
  BytesReturned: Cardinal;
begin
  SetKeepAliveValue:= false;
  FillChar(KeepAliveIn, SizeOf(KeepAliveIn), 0);
  KeepAliveIn.OnOff:= OnOff;
  KeepAliveIn.KeepAliveTime:= Time;
  KeepAliveIn.KeepAliveInterval:= Interval;
if WSAIoctl(Socket, SIO_KEEPALIVE_VALS, @KeepAliveIn, SizeOf(KeepAliveIn), nil, 0, &BytesReturned, nil, nil)= 0 then SetKeepAliveValue:= true;
end;

--
Denis Gottardello
Sintesi S.r.l.
049.9301135

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to