一个简单的例子,把QQ的服务器地址设为自己的IP,端口为程序中UDP的本地端口
procedure TForm1.udpDataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
var
buf:array of char;
Stream:TMemoryStream;
begin
setlength(buf,NumberBytes);
udp.ReadBuffer(buf[0],NumberBytes);
log.Lines.add(fromip+':'+inttostr(port));
if fromip='192.168.1.2' then
begin
udp.RemoteHost:='sz.tencent.com';
udp.RemotePort:=8000;
Stream:=TMemoryStream.Create;
Stream.Write(buf[0],numberbytes);
Stream.Seek(soFromBeginning,0);
udp.SendStream(Stream);
Stream.Free;
end
else
begin
udp.RemoteHost:='192.168.1.2';
udp.RemotePort:=4000;
Stream:=TMemoryStream.Create;
Stream.Write(buf[0],numberbytes);
Stream.Seek(soFromBeginning,0);
udp.SendStream(Stream);
Stream.Free;
end;
end;
不知道你要的是不是这样的。。。