Recent

Author Topic: Sending a message to another app  (Read 2283 times)

yazzdi

  • New Member
  • *
  • Posts: 16
Sending a message to another app
« 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?

mr-highball

  • Full Member
  • ***
  • Posts: 233
    • Highball Github
Re: Sending a message to another app
« Reply #1 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.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Sending a message to another app
« Reply #2 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.
« Last Edit: August 14, 2019, 08:54:32 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

julkas

  • Guest
Re: Sending a message to another app
« Reply #3 on: August 14, 2019, 01:01:44 pm »
I suggest messaging over UDP. Easy to progam, just write your simple protocol.

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Sending a message to another app
« Reply #4 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.

 

TinyPortal © 2005-2018