Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 01/14/20 in Posts

  1. Hello, I am using Delphi 10.3.3, Indy 10.6.2.5366 (stock Indy version) I am trying to listen broadcast UDP messages on Android (exact version I am testing is 4.4.2, I need to support latest versions, too) connected to a local WiFi. Broadcast messages will be sent in same network. I have found this page https://stackoverflow.com/questions/19040674/delphi-xe5-tidudpserver-does-not-receive-anything-on-android and tried to do it as to my understanding. Project has CHANGE_WIFI_MULTICAST_STATE permission set. UDP server parameters are as following at design time and everything else is left as default: TIdUDPServer.Active = False TIdUDPServer.BroadcastEnable = True TIdUDPServer.DefaultPort = 8080 I have following code where timer is activated as last line in OnFormCreate() event and has 0.5 seconds delay: procedure TForm3.tmrCheckPhoneServiceTimer(Sender: TObject); var WifiManagerObj: JObject; begin // Run just once tmrCheckPhoneService.Enabled := False; // Get necessary OS settings to receive broadcast messages Log('Getting multicast lock...'); WifiManagerObj := TAndroidHelper.Context.getSystemService(TJContext.JavaClass.WIFI_SERVICE); FWifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID); FMulticastLock := FWifiManager.createMulticastLock(StringToJString('LightFactory Remote')); FMulticastLock.setReferenceCounted(True); FMulticastLock.acquire(); // Try to open a port on Android by sending a broadcast message Log('Sending a broadcast message...'); IdUDPServer1.Broadcast('test', IdUDPServer1.DefaultPort); // Now we can start to listen Log('Activating UDP listener...'); IdUDPServer1.Active := True; if FPhoneDialerService = nil then begin TDialogService.ShowMessage('PhoneDialer service not supported'); Exit(); end; PermissionsService.RequestPermissions([FCallPhonePermission], MakePhoneCallPermissionRequestResult, DisplayRationale); end; I have following code in my OnDestroy() event: procedure TForm3.FormDestroy(Sender: TObject); begin // Stop listenning. IdUDPServer1.Active := False; // Release multicast lock FMulticastLock.release(); end; My broadcast listening code is as following: procedure TForm3.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle); var Data: string; begin Data := TEncoding.Default.GetString(AData); TThread.Queue(nil, procedure begin Log('Incoming broadcast message from: ' + ABinding.PeerIP) end); if SameText(Data, 'mytriggerphrase') then begin TThread.Queue(nil, procedure begin TestConnection(ABinding.PeerIP) end); end; end; After I run the app, I have following in my log: 2020-01-14 00:59:33.697 Getting multicast lock... 2020-01-14 00:59:33.736 Sending a broadcast message... 2020-01-14 00:59:33.740 Activating UDP listener... 2020-01-14 00:59:33.804 Incoming broadcast message from: 192.168.1.186 That IP number in above log belongs to Android device itself. I have following problems that I could not figure a solution: 1- I do not get any other broadcast message from my PC application which is sending one broadcast message each second. Is there anything I am doing wrong for that to happen? 2- I get segmentation fault (11) when closing my app. Detailed call stack and exact line is in attached picture. This happens each and every close. I did not understand why. Lastly, I am not sure if my code is doing it correct to keep multicast lock thru all run-time. I read a suggestion to release a multicast lock once finished with it in order to save battery life. So, I wonder if I can release multicast lock right after enabling my TIdUDPServer? Any help is appreciated. Thanks & regards, Ertan
  2. I can't really comment on the multicast issue, especially on Android. But if you are really doing multicasting, why are you using TIdUDPServer? That is not a multicast-enabled component. Indy has separate TIdIPMCastClient and TIdIPMCastServer components specifically for multicast. For UDP, assuming a plain vanilla network broadcast is in fact, being used, are you setting up the TIdUDPServer.Bindings collection at all prior to activating the server? One problem I do see is your use of TThread.Queue() captures the ABinding object, which is no longer valid once the TIdUDPServer is freed. Delphi anonymous procedures capture variables, not values. You should use TThread.Queue() more like this instead: procedure TForm3.QueueLog(const AMsg: string); begin TThread.Queue(nil, procedure begin Log(AMsg); end ); end; procedure TForm3.QueueTestConnection(const APeerIP: string); begin TThread.Queue(nil, procedure begin TestConnection(APeerIP); end ); end; procedure TForm3.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle); var Data: string; begin Data := TEncoding.Default.GetString(AData); QueueLog('Incoming broadcast message from: ' + ABinding.PeerIP); if SameText(Data, 'mytriggerphrase') then begin QueueTestConnection(ABinding.PeerIP); end; end;
  3. pyscripter

    TButtonedEdit Styles and transparency

    https://quality.embarcadero.com/browse/RSP-26633 The report contains a solution.
  4. Attila Kovacs

    In-App Clipboard

    Hm, thanks Lars, this will be a good start. Hope I can isolate, not just watch. Lets see!
  5. Lars Fosdal

    In-App Clipboard

    A bit of Googling dug up http://delphidabbler.com/articles?article=9 with src https://bitbucket.org/delphidabbler/article-9-demo/src/master/ which demos the basics - but you'd still need to do the checks to figure out what is relevant to your own app.
  6. Attila Kovacs

    In-App Clipboard

    Thanks @Ugochukwu Mmaduekwe, no problem, I just wanted to inform if there is already something for that. I'll check hooking up some windows messages.
  7. Lars Fosdal

    In-App Clipboard

    I haven't seen one, but I haven't really been looking for one. I guess you have these links already... https://docs.microsoft.com/en-gb/windows/win32/dataxchg/clipboard https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-setclipboardviewer
×