UDP og Wolfenstein-servere
Jeg fandt et eksempel, som jeg ikke kan få til at virke med UDP komponentet i Delphi 5. Kan i hjælpe mig?/Allan
Eks :
procedure TQ3Master.Execute;
var
nReturn:Integer;
sBuf:Array[0..32000] of Char;
dEndTime:TDateTime;
nCurr:Integer;
lFoundEOT:Boolean;
udpConnection:TIdUdpClient;
begin
udpConnection:=TIdUdpClient.Create(nil);
udpCOnnection.Host:=sMasterIp;
udpConnection.Port:=27950;
udpConnection.ReceiveTimeout:=2000;
udpConnection.BroadcastEnabled:=False;
if Protocol=0 then
Protocol:=48;
StrCopy(sBuf,PChar(Format('xxxxgetservers %d'#10,[Protocol])));
sBuf[0]:=#255;
sBuf[1]:=#255;
sBuf[2]:=#255;
sBuf[3]:=#255;
udpConnection.Send(sBuf);
dEndTime:=Now+EncodeTime(0,0,6,0);
lFoundEOT:=False;
while (Now<dEndTime) and (not Terminated) do
begin
nReturn:=udpConnection.ReceiveBuffer(sBuf,SizeOf(sBuf));
if (nReturn>0) and (nReturn<32000) then
begin
{Parse out the IP addresses and ports}
sBuf[nReturn]:=#0;
nCurr:=22;
while nCurr<nReturn-6 do
begin
Inc(nCurr);
Addr.S_un_b.s_b1:=sBuf[nCurr];
Addr.S_un_b.s_b2:=sBuf[nCurr+1];
Addr.S_un_b.s_b3:=sBuf[nCurr+2];
Addr.S_un_b.s_b4:=sBuf[nCurr+3];
Port:=MakeWord(Ord(sBuf[nCurr+4]),Ord(sBuf[nCurr+5]));
Port:=ntohs(Port);
Synchronize(AddIpToList);
Inc(nCurr,6);
end;
if strcomp(@sBuf[nReturn-3],'EOT')=0 then
lFoundEOT:=True;
end
else
if lFoundEOT then
dEndTime:=Now;
end;
udpConnection.Free;
end;
