我有一个使用idHttpServer开发的Web服务器应用程序。当客户端连接时,请执行我的Web服务器,并且由于某种未知原因而断开连接(不是正常断开连接),则不会通知我的Web服务器。我知道这是正常的行为,但是我需要知道客户死亡的时间。
有几种方法可以做到这一点。我知道2种好方法:
1-实施心跳机制。客户端套接字通知服务器它仍在运行(需要一些工作和一些代码才能使其工作)
2- TCP保持活动。这是我最喜欢的方式,因为它不需要太多的代码和工作。但是我对此有一些疑问。
编辑
我正在使用Delphi 2010和他们svn的最后一个Indy10源代码。
我正在尝试将记录从服务器传输到客户端,直接使用.SendBuf().
但是,这个记录有一个动态数组的成员,我在某处读取(这里是SOF),当发送记录时,成员必须是STATIC(固定长度),但问题是......我无法确定如何我将发送的许多论据(将来).
我怎么解决这个问题 ?
procedure TServerClass.SendBufToSocket(const vmName: TVMNames; const vmArgs: Array of TValue);
var
// this record is sent to client
// vmName = method to be called [in]
// vmArgs = Argument for the method [in, optional]
BufRec: packed record
vmName: array[0..49] of char;
vmArgs: Array of TValue;
end;
s: string;
i: integer;
begin
// convert enum method name to string
s:= GetEnumName(TypeInfo(TVMNames), Integer(vmName));
// copy method name to record
lstrcpy(BufRec.vmName, pChar(s));
// copy arg array to record
SetLength(BufRec.vmArgs, …Run Code Online (Sandbox Code Playgroud)