Delphi Indy TCP服务器-已删除断开连接的句柄?
我有一个带有Indy TCPServer和TCPClient的Delphi应用程序。我使用Delphi Indy TCP服务器-已删除断开连接的句柄?,delphi,indy,Delphi,Indy,我有一个带有Indy TCPServer和TCPClient的Delphi应用程序。我使用AContext.Bindind.Handle标识每个连接(错误?) 因此,我有一个显示连接的网格,我将在断开连接后删除该条目: procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext); var I:Integer; begin for I := 0 to gridClients.RowCount - 1 do begin if gri
AContext.Bindind.Handle
标识每个连接(错误?)
因此,我有一个显示连接的网格,我将在断开连接后删除该条目:
procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
for I := 0 to gridClients.RowCount - 1 do
begin
if gridClients.Cells[0, I] = IntToStr(AContext.Binding.Handle) then
begin
gridClients.Rows[I].Delete(I);
end;
end;
WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;
但是在断开连接事件中,句柄已经是空的(它曾经是401xxxxx,所以是最后一个整数)
想法?您没有提到您使用的是哪个版本的Delphi或Indy,但以下内容适用于D2010和Indy 10.x 我使用了“AContext.Data”属性来标识客户机。我通常在那里创建一个对象,并在断开连接事件发生时释放它 新的OnConnect()代码: 修改了以下OnDisconnect()代码:
procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
for I := 0 to gridClients.RowCount - 1 do
begin
if gridClients.Cells[0, I] = IntToStr(AContext.Data) then
begin
gridClients.Rows[I].Delete(I);
end;
end;
WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;
您没有提到您使用的是哪个版本的Delphi或Indy,但以下内容适用于D2010和Indy 10.x 我使用了“AContext.Data”属性来标识客户机。我通常在那里创建一个对象,并在断开连接事件发生时释放它 新的OnConnect()代码: 修改了以下OnDisconnect()代码:
procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
for I := 0 to gridClients.RowCount - 1 do
begin
if gridClients.Cells[0, I] = IntToStr(AContext.Data) then
begin
gridClients.Rows[I].Delete(I);
end;
end;
WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;
好建议。始终使用您自己的标识符,不要将Indy的内部对象和句柄用作ID。好建议。始终使用您自己的标识,不要将Indy的内部对象和句柄用作标识。