MacOS Inter-process communication?

141 views
Skip to first unread message

eb1

unread,
Feb 23, 2021, 9:40:04 AM2/23/21
to wx-dev
Hello,

I was wondering if there is an API that implements the NSDistributedNotificationCenter class on MacOS, to allow for inter-app communication -- or if there's another way to do this on the Mac. Any info would be appreciated.

-e

Vadim Zeitlin

unread,
Feb 23, 2021, 6:57:10 PM2/23/21
to wx-...@googlegroups.com
On Tue, 23 Feb 2021 06:40:04 -0800 (PST) eb1 wrote:

e> I was wondering if there is an API that implements the
e> NSDistributedNotificationCenter class on MacOS, to allow for inter-app
e> communication -- or if there's another way to do this on the Mac. Any info
e> would be appreciated.

No, I'm afraid there is nothing wrapping NSDistributedNotificationCenter
in wx API. I am not even sure if it's possible to provide something
equivalent for the other platforms, so perhaps the only solution is to just
write Mac-specific code using it directly.

Of course, if you can propose some (maybe higher-level) API wrapping it
that would be also implementable on the other platforms, it would be nice
to add it to wx -- even if it's initially implemented only for Mac (but
ideal would be to implement it for at least one other platform to prove
that it's indeed possible to do it).

So the question is what exactly would you use it for in your application
and how would you do the same thing under the other platforms?

Thanks,
VZ

eb1

unread,
Feb 25, 2021, 9:30:31 AM2/25/21
to wx-dev
Thanks so much for the reply.

There's always a story behind these requests. :-) We have an app that does inter-process communication with other apps in Windows by overriding MSWWindowProc() and peeking for a custom / specific windows message string registered through RegisterWindowMessage() (and sent through ::SendMessage()). For our use case, the messages are used to synchronize scrolling between apps that are displaying the same text.

For the Mac, a couple of the apps we're communicating with are using the NSDistributedNotificationCenter class to send/receive these messages. It looks like it's a different paradigm than what we did on Windows -- using the observer pattern from what I can tell, rather than doing HWND_BROADCAST messages to any window that might possibly want to know about the notification. 

I suppose an API that worked under Windows could take the SendMessage() stuff and wrap it in an observer pattern as well -- the SendMessage() call does allow for specific window handles to be used, so the Subject class could send to all Observers in its list (I guess discarding HWNDs that are no longer viable from its list as it goes). You'd have to add a note in the docs to be aware of UIPI restrictions (i.e., that the message won't get through to observer processes with the wrong privs).

-e

Tobias T

unread,
Feb 26, 2021, 5:22:19 AM2/26/21
to wx-dev
Maybe I'm missing something, but it sounds like you could use wxConnection which would work on windows and macOS.

Vadim Zeitlin

unread,
Feb 26, 2021, 5:15:17 PM2/26/21
to wx-...@googlegroups.com
On Thu, 25 Feb 2021 06:30:31 -0800 (PST) eb1 wrote:

e> Thanks so much for the reply.
e>
e> There's always a story behind these requests. :-) We have an app that does
e> inter-process communication with other apps in Windows by overriding
e> MSWWindowProc() and peeking for a custom / specific windows message string
e> registered through RegisterWindowMessage() (and sent through
e> ::SendMessage()). For our use case, the messages are used to synchronize
e> scrolling between apps that are displaying the same text.

Thanks for the explanation!

So you basically have a windows message-based IPC mechanism allowing to
exchange the scroll position, right? As already mentioned in another reply,
wx does provide IPC classes (wxConnection) that use DDE under MSW and
(local domain) sockets elsewhere. This is a bit heavier than your approach,
but I think it would still work for you.

e> For the Mac, a couple of the apps we're communicating with are using the
e> NSDistributedNotificationCenter class to send/receive these messages.

But, of course, wxIPC is not interoperable with this class. I don't know
if we can implement wxIPC functionality on top of it and, even if we could,
whether we could make it compatible with the existing users of the
messages.

e> It looks like it's a different paradigm than what we did on Windows --
e> using the observer pattern from what I can tell, rather than doing
e> HWND_BROADCAST messages to any window that might possibly want to know
e> about the notification.

This seems to be more or less compatible with DDE "advice loop" but,
again, I don't know if it can be mapped reasonably well if you get into the
details.

So, in practice, you can either just use the existing wxIPC classes if you
don't need compatibility with the existing applications or write
Mac-specific code if you do need to use exactly the same messages from
NSDistributedNotificationCenter as the existing applications use. It would
still be nice to have wxIPC implementation using a more Mac-native
mechanism but I don't think it's going to happen in the near future.

Regards,
VZ
Reply all
Reply to author
Forward
0 new messages