如何判斷一個tcp空連接(50分)

  • 主题发起人 主题发起人 melice
  • 开始时间 开始时间
barton能否留个im,有些事情想具体请教一下
 
im是什么?:(
QQ:47588433
UC:36981604
E-Mail:barton131420@163.com

to 张无忌:
最短为0,最长为2小时。你可以自己找找这方面的文章看看。
 
在阻塞模型下。 即使设置了超时时间, 最短也需要2个小时 TCP 才会自动检查。
你可以用实际去验证一下
 


各位 我们转到下面一贴讨论吧
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1984522
 
在Win2000下:
var
Keepalive: tcp_keepalive;
X: DWORD;
...
Keepalive.onoff := 1;
Keepalive.KeepaliveTime := 180000; //3分钟
Keepalive.KeepaliveInterval := 30000; //30秒
WSAIoctl(ListenSocket, SIO_KEEPALIVE_VALS, @Keekalive, SizeOf(tcp_keepalive),
nil, 0, X, nil, nil);
可惜我手头上的Winsock2没有声明SIO_KEEPALIVE_VALS常量和Tcp_keepalive结构,但我看
过的那篇文章和MSDN上都有相关的描述。
 
这个有:
{ Winsock2 TCP/IP IOCTL API interface Unit for Object Pascal }
{ http://delphi-jedi.org/ units: JwaMSTcpIP.pas,JwaWinSock2.pas }
type
u_long = Cardinal;

tcp_keepalive = record
onoff: u_long;
keepalivetime: u_long;
keepaliveinterval: u_long;
end;
TTCPKeepAlive = tcp_keepalive;
PTCPKeepAlive = ^TTCPKeepAlive;

const
IOCPARM_MASK = $7f; // parameters must be < 128 bytes
IOC_VOID = $20000000; // no parameters
IOC_OUT = $40000000; // copy out parameters
IOC_IN = DWORD($80000000); // copy in parameters
IOC_INOUT = DWORD(IOC_IN or IOC_OUT);

IOC_UNIX = $00000000;
IOC_WS2 = $08000000;
IOC_PROTOCOL = $10000000;
IOC_VENDOR = $18000000;

// New WSAIoctl Options
SIO_RCVALL = IOC_IN or IOC_VENDOR or 1;
SIO_RCVALL_MCAST = IOC_IN or IOC_VENDOR or 2;
SIO_RCVALL_IGMPMCAST = IOC_IN or IOC_VENDOR or 3;
SIO_KEEPALIVE_VALS = IOC_IN or IOC_VENDOR or 4;
SIO_ABSORB_RTRALERT = IOC_IN or IOC_VENDOR or 5;
SIO_UCAST_IF = IOC_IN or IOC_VENDOR or 6;
SIO_LIMIT_BROADCASTS = IOC_IN or IOC_VENDOR or 7;
SIO_INDEX_BIND = IOC_IN or IOC_VENDOR or 8;
SIO_INDEX_MCASTIF = IOC_IN or IOC_VENDOR or 9;
SIO_INDEX_ADD_MCAST = IOC_IN or IOC_VENDOR or 10;
SIO_INDEX_DEL_MCAST = IOC_IN or IOC_VENDOR or 11;

// Values for use with SIO_RCVALL* options
RCVALL_OFF = 0;
RCVALL_ON = 1;
RCVALL_SOCKETLEVELONLY = 2;
 
后退
顶部