Ci sono pochi dispositivi uPNP nella mia rete. Sto cercando di inviare la richiesta M-SEARCH alla rete e spero di ricevere alcune risposte da esso. Questo è quello che sto provando:Posso utilizzare IdUDPClient per inviare la richiesta M-SEARCH?
var sIP, sOut: string;
iPort: Word;
S: TStringBuilder;
begin
S := TStringBuilder.Create;
try
S.Append('M-SEARCH * HTTP/1.1').AppendLine
.Append('HOST: 239.255.255.250:1900').AppendLine
.Append('MAN: "ssdp:discover"').AppendLine
.Append('MX: 10').AppendLine
.Append('ST: ssdp:all').AppendLine;
IdUDPClient1.ReceiveTimeout := 3000;
IdUDPClient1.Broadcast(S.ToString, 1900, '239.255.255.250');
sOut := IdUDPClient1.ReceiveString(sIP, iPort);
Memo1.Lines.Add(sIP);
Memo1.Lines.Add(IntToStr(iPort));
Memo1.Lines.Add(sOut);
finally
S.Free;
end;
end;
Non ricevo nulla dal client UDP. Uso Wireshark per monitorare il traffico di rete e nessun messaggio è stato inviato dal mio host.
Qualche idea? Grazie.
ho trovato la risposta infine:
uses
System.SysUtils, IdUDPClient, IdStack;
var S: TStringBuilder;
U: TIdUDPClient;
iPeerPort: Word;
sPeerIP, sResponse: string;
begin
U := TIdUDPClient.Create(nil);
S := TStringBuilder.Create;
try
S.Append('M-SEARCH * HTTP/1.1').AppendLine
.Append('HOST: 239.255.255.250:1900').AppendLine
.Append('MAN: "ssdp:discover"').AppendLine
.Append('MX: 3').AppendLine
.Append('ST: ssdp:all').AppendLine
.AppendLine;
U.BoundIP := GStack.LocalAddress;
U.Send('239.255.255.250', 1900, S.ToString);
U.ReceiveTimeout := 1000;
repeat
sResponse := U.ReceiveString(sPeerIP, iPeerPort);
if iPeerPort <> 0 then begin
WriteLn(Format('%s:%d', [sPeerIP, iPeerPort]));
WriteLn(sResponse);
end;
until iPeerPort = 0;
ReadLn;
finally
S.Free;
U.Free;
end;
end.
aggiungo un nuovo AppendLine() all'oggetto stringbuilder, ma non ho ricevuto alcuna risposta. Inoltre, non ho notato la richiesta inviata dal mio ospite durante il monitoraggio del traffico tramite WireShark. –
Sei sicuro che '239.255.255.250' è l'IP di trasmissione corretto per la tua LAN? Quale IP e sottorete locale sono assegnati al PC del tuo cliente? –
Se trasmetto a 239.255.255.255, posso vedere il traffico inviato dal mio host. Trasmesso a 239.255.255.250, non è stato rilevato alcun traffico. –