我做过类oicq的软件。是用UDP实现三层查询返回好友结果的。
大概是用到TListString
//发送
function Tfrmmain.qqOnline(const iv_serverip:string;const iv_serverport:integer):boolean;
var myStream:TMemoryStream;
TmpStr:String;
ipport:TStringList;
begin
UDPOnline.RemoteHost := iv_serverip;
UDPOnline.RemotePort := iv_serverport;
ipport := TStringList.Create;
ipport.Values['localip'] := localip;
ipport.Values['localport'] := localport;// 关键,返回服务器的数据字段的值
myStream := TMemoryStream.Create;
TmpStr := 'QQOnline' + ipport.Text;
try
myStream.Write(TmpStr[1],Length(TmpStr));
UDPOnline.SendStream(myStream);
finally
myStream.Free;
end;
ipport.Free;
end;
//接受
procedure Tfrmmain.UDPOnlineDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var receiveStream:TMemoryStream;
TmpStr:String;
receiveData:TStringList;
begin
receiveStream := TMemoryStream.Create;
try
UDPOnline.ReadStream(receiveStream);
SetLength(TmpStr,NumberBytes);
receiveStream.Read(TmpStr[1],NumberBytes);
if Copy(TmpStr,1,12) = '2125QQOnline' then
begin
receiveData := TStringList.Create;
try
receiveData.Text := Copy(TmpStr,13,Length(TmpStr));
ShowMessage(receiveData.Values['localip']); //接收
ShowMessage(receiveData.Values['localport']);
finally
receiveData.Free;
end;
end; // end if
finally
receiveStream.Free;
end;
end;
//----------
//能给分了吧。