Lazarus

Installation => Mac OS X => Topic started by: yazzdi on August 13, 2019, 10:58:41 pm

Title: Sending a message to another app
Post by: yazzdi on August 13, 2019, 10:58:41 pm
I have a Mac 64 bit FPC/Lazarus app. I have another app that I also wrote (in C). I need the two apps to be able to due very simple messaging to each other. Something like SendMessage on Windows. Not sharing data, just notifying the other app when something needs to be done. Sending a message with an integer parameter would be sufficient.

I’m looking for the simplest method to do this, does anyone have any suggestions?
Title: Re: Sending a message to another app
Post by: mr-highball on August 14, 2019, 01:28:36 am
Not the most elegant solution, but both programs could have a "hotfolder" they monitor for message files. When they detect a file, they read the message and delete it.

Another similar approach is to used a shared sqlite db with a queue table that is has a "source" and "message" column (think file approach just inside of a db).

A third approach could use sockets/http server that each application hosts, then when one app needs to notify the other, a post request/write to socket can be done. A bit more complicated but doesn't involve polling something.

Just some suggestions, there's probably a better way, I'm just not a mac user.
Title: Re: Sending a message to another app
Post by: Thaddy on August 14, 2019, 08:24:45 am
Use pipes or better use ipc. See the simpleipc example in the fcl-process package.

A good overview is here: https://www.slideshare.net/Hem_Dutt/ipc-on-mac-osx all of which can be done with Freepascal.
Title: Re: Sending a message to another app
Post by: julkas on August 14, 2019, 01:01:44 pm
I suggest messaging over UDP. Easy to progam, just write your simple protocol.
Title: Re: Sending a message to another app
Post by: ChrisR on August 24, 2019, 01:16:08 pm
I have used shared memory. If you look at the unit "yokesharemem.pas" in one of my Github projects you will find examples. In my case, I always share a fixed number of values, so it is a very simple case where the number of bytes shared is known ahead of time.