我想你可能需要delphi代码:
TWSAIoctl = function (s: TSocket;
cmd: DWORD;lpInBuffer: PCHAR;
dwInBufferLen
WORD;lpOutBuffer: PCHAR;
dwOutBufferLen: DWORD;
lpdwOutBytesReturned: LPDWORD;lpOverLapped: POINTER;
lpOverLappedRoutine: POINTER): Integer;
stdcall;
定义
tcp_keepalive = record
onoff: Integer;
keepalivetime: Integer;
keepaliveinterval: Integer;
end;
TTCP_KEEPALIVE = tcp_keepalive;
PTCP_KEEPALIVE = ^tcp_keepalive;
FWSAIoctl: TWSAIoctl;
inKeepAlive,OutKeepAlive:TTCP_KEEPALIVE;
procedure TfrmMain.LoadWs2_32dll;
begin
Fhand_dll := LoadLibrary('ws2_32.dll');
if (Fhand_dll <> 0) then
begin
@FWSAIoctl := GetProcAddress(Fhand_dll, 'WSAIoctl');
end;
end;
procedure TfrmMain.FreeWs2_32dll;
begin
if Fhand_dll <> 0 then
FreeLibrary(Fhand_dll);
end;
在服务端接收socket连接后
inKeepAlive.onoff:=1;
//设置3秒钟时间间隔
inKeepAlive.keepalivetime:=3000;
//开始首次KeepAlive探测前的TCP空闭时间
//设置每3秒中发送1次的心跳
inKeepAlive.keepaliveinterval:=1;
//两次KeepAlive探测间的时间间隔
insize:=sizeof(TTCP_KEEPALIVE);
outsize:=sizeof(TTCP_KEEPALIVE);
fWSAIoctl(sktGciSendSocket, SIO_KEEPALIVE_VALS, @inKeepAlive, SizeOf(tcp_keepalive),
nil, 0, @t, nil, nil);
代码你自己组织一下