Il 15/01/2013 15:43, Dietrich Hasselhorn ha scritto:
> Try to change three items:
>
> a. remove the line keepalive.keepalivetime:=10000;
> b. increase keepaliveinterval from 1 to 10 seconds
> b. also set the SocketOptions REUSE_ADDR
>
> this should take care of the problem.
>
> Regards,
>
>       Dietrich Hasselhorn
I'm not sure if that this is right for you but, in order to use the keep 
alive feature I use these functions:


           ClientSocket:= ServerSocket.Accept;
           if ServerSocket.LastError= 0 then begin
             SetKeepAliveStatus(ClientSocket, 1);
             SetKeepAliveValue(ClientSocket, 1, 500, 500);
TLThTcpServerConn.Add(ThTcpServerConn.Create(ClientSocket));
           end;

______



unit USocketOptions;

interface

uses
   System.Win.ScktComp, Winsock, Windows, Winsock2;

function GetKeepAliveStatus(Socket: NativeInt; OptVal: PInteger): Boolean;
function SetKeepAliveStatus(Socket: NativeInt; OptVal: Integer): Boolean;
function SetKeepAliveValue(Socket: NativeInt; OnOff, Time, Interval: 
Integer): Boolean;

implementation

function GetKeepAliveStatus(Socket: NativeInt; OptVal: PInteger): Boolean;
var
   Len: Integer;
begin
   GetKeepAliveStatus:= false;
   Len:= SizeOf(OptVal^);
   if GetSockOpt(Socket, SOL_SOCKET, SO_KEEPALIVE, @(OptVal^), Len)= 0 
then GetKeepAliveStatus:= true;
end;

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;

end.

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


------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to