Make SSDP discovery on FMX (Android) Delphi

  

I’m trying to do SSDP discovery on a little FMX(Android) app of myself (to discover my ambilight server).
This is where I’m right now :
procedure TfrmHyperionManager.searchSSDP;
var
_udpClient: TIdUDPClient;
_peerPort: Word;
_peerIP, _response: string;
begin
lblServers.Text:= ‘Recherche de serveurs Hyperion…’;
_udpClient:= TIdUDPClient.Create(nil);
try
{$IFDEF ANDROID}
_udpClient.Active := true;
{$ENDIF}
_udpClient.BoundIP:= GStack.LocalAddress;
_udpClient.ReceiveTimeout:= 3000;
_udpClient.Send( ‘239.255.255.250’, 1900, ‘M-SEARCH * HTTP/1.1’ + #13#10 +
‘HOST: 239.255.255.250:1900’ + #13#10 +
‘MAN: "ssdp:discover"’+ #13#10 +
‘MX: 3’+ #13#10 +
‘ST: urn:hyperion-project.org:device:basic:1’+ #13#10 +
#13#10 );
repeat
_response:= _udpClient.ReceiveString( _peerIP, _peerPort );
if ( _peerPort <> 0 ) then
FServersList.Add( _peerIP );
until ( _peerPort = 0 );

fillServerCombo;
finally
_udpClient.Free;
end;
end;

Now that works on my phone (Android 10), but it doesn’t on some other phones…it is a bit of hit and miss, sometimes it works on a phone model (let’s say Redmi Note 7) and it does not on the same model of another person…(app does not open).
Do I do it the right way ?
If not can you give me some example of how to do this properly ?
I’m sorry for this question but it is my first attempt at an Android app with Delphi, the rest of time I only do windows development with Delphi for my company.
Many thanks.

Comments are closed.