Z
zylsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
我想IdTCPServer让客户端链接后显示在Tlistview中,断开后清除,代码:
type
PClient = ^TClient;
TClient = record
IP : String[20];
Thread : Pointer;
end;
Clients : TThreadList;
......
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
var s,s1,s2,s3:string;
NewClient: PClient;
begin
AThread.Data := TObject(AThread.Connection.LocalName);
Memo1.Lines.Add(TimeToStr(Time) + '来自计算机(名字)"' + AThread.Connection.LocalName + '"的链接!');
Memo1.Lines.Add(TimeToStr(Time) + '来自计算机(IP)"' + AThread.Connection.Socket.Binding.PeerIP + '"的链接!');
s:=AThread.Connection.Socket.Binding.PeerIP;
s1:='';
s2:='';
s3:=('就绪');
with Lv.Items.Add do
begin
Caption :=s;
SubItems.Add(s1);
SubItems.Add(s2);
SubItems.Add(datetimetostr(now));
SubItems.Add(s3);
N:=N+1;
end;
GetMem(NewClient, SizeOf(TClient));
NewClient.IP := s;
NewClient.Thread := AThread;//binding the thread by the qq number
AThread.Data := TObject(NewClient);
try
Clients.LockList.Add(NewClient);
finally
Clients.UnlockList;
end;
end;
为什么客户端断开后触发不了IdTCPServer1Disconnect事件?
不知道那地方代码错误?或有什么好办法解决!!!???
type
PClient = ^TClient;
TClient = record
IP : String[20];
Thread : Pointer;
end;
Clients : TThreadList;
......
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
var s,s1,s2,s3:string;
NewClient: PClient;
begin
AThread.Data := TObject(AThread.Connection.LocalName);
Memo1.Lines.Add(TimeToStr(Time) + '来自计算机(名字)"' + AThread.Connection.LocalName + '"的链接!');
Memo1.Lines.Add(TimeToStr(Time) + '来自计算机(IP)"' + AThread.Connection.Socket.Binding.PeerIP + '"的链接!');
s:=AThread.Connection.Socket.Binding.PeerIP;
s1:='';
s2:='';
s3:=('就绪');
with Lv.Items.Add do
begin
Caption :=s;
SubItems.Add(s1);
SubItems.Add(s2);
SubItems.Add(datetimetostr(now));
SubItems.Add(s3);
N:=N+1;
end;
GetMem(NewClient, SizeOf(TClient));
NewClient.IP := s;
NewClient.Thread := AThread;//binding the thread by the qq number
AThread.Data := TObject(NewClient);
try
Clients.LockList.Add(NewClient);
finally
Clients.UnlockList;
end;
end;
为什么客户端断开后触发不了IdTCPServer1Disconnect事件?
不知道那地方代码错误?或有什么好办法解决!!!???