在DELPHI的TCP/IP的C/S聊天室中,在SERVER端中如何主动删除与客户端建立的SOCKET通道呢?
也就是我要主动的删除某一个指定的客户,或者说是某一个因其它原因突然失去和SERVER端联系的客户呢(指客户端在没有事先通知要离开服务端的情况下)?
也就是我要主动的删除某一个指定的客户,或者说是某一个因其它原因突然失去和SERVER端联系的客户呢(指客户端在没有事先通知要离开服务端的情况下)?
调试欢乐多
ServerSocket1.Socket.Connections[0].Close;
---------------------------------------
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var
ii,jj:integer;
User :string;
begin
for ii:=0 to ListView1.Items.Count -1 do
begin
if listview1.Items.Item[ii].SubItems.Strings[2] =IntToStr(Socket.RemotePort) then
begin
for jj :=0 to ListView1.Items.Count -1 do
begin
Label_count.Caption :=Inttostr(ListView1.Items.Count -1) + '个';
//在线人数
serversocket1.Socket.Connections[jj].SendText('删除用户@#!^' + user+'^'+Label_count.Caption);
//Connections[jj] 为连接的客户端
end;
memo1.Lines.Add(datetostr(date) +' '+timetostr(time)+ '==>>'+listview1.Items[ii].Caption +'走了!' );
listview1.Items.Item[ii].Delete(); //删除
Display(socket.RemoteHost+'走了');
exit;
end
end;