贴出源码:
procedure Tfrm_main.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
re
char;
sbuf:string;
ip,name:string;
i:integer;
count:integer;
begin
re:=nil;
while socket.receivelength>0 do
begin
re:=allocmem(socket.ReceiveLength);
try
socket.ReceiveBuf(re^,socket.receivelength);
sbuf:=strpas(re);
finally
freemem(re);
end;
end;
if pos('logo',sbuf)>0 then
begin
i:=pos('@',sbuf);
name:=copy(sbuf,5,i-5);
ip:=copy(sbuf,i+1,length(sbuf)-i);
try
adodataset1.Open;
adodataset1.Insert;
adodataset1.FieldByName('ip').AsString:=ip;
adodataset1.FieldByName('name').AsString:=name;
adodataset1.Post;
adodataset1.Close;
except
messagebox(0,'未知错误!','错误',mb_ok);
end;
count:=serversocket1.Socket.ActiveConnections;
for i:=1 to count-1 do
begin
adodataset1.Open;
while not adodataset1.Eof do
begin
serversocket1.Socket.Connections
.SendText('client'+adodataset1.Fieldbyname('name').asstring);
//上面这句
adodataset1.Next;
end;
adodataset1.Close;
end;
end;
if pos('down',sbuf)>0 then
begin
name:=copy(sbuf,5,length(sbuf)-4);
adodataset1.Open;
adodataset1.Locate('name',name,[]);
adodataset1.Delete;
adodataset1.Close;
end;
end;