Jump to content
softtouch

Some sort of IPC cross platform?

Recommended Posts

I am looking for some sort of IPC which works cross platform.

The purpose is to start other executables from a main program and communicate with them, sending data and receive results for example.

It should work on Windows and also on macOS.

Unfortunately, I could not finds anything useful.

Does anybody has a clue or hint or anything?

Share this post


Link to post

Pipes are the best for apps you launch and control. The easiest implementation at the sub app side is just ReadLn/WriteLn

Share this post


Link to post

I cant get tcp (using Indy) working. On Win is works, running the same on mac, it crash with some error #5.

Isn't there somewhere a solution that actually works?

Share this post


Link to post

I use mORMot for this because calling a method or an interface in another process is just like calling a method/interface in the same process.

And the communication protocol can be tcp/ip or named pipes.

 

On process B you define and implement an interface:

type
  ICalculator = interface(IInvokable)
    ['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
    /// add two signed 32-bit integers
    function Add(n1,n2: integer): integer;
  end;

  TServiceCalculator = class(TInterfacedObject, ICalculator)
  public
    function Add(n1,n2: integer): integer;
  end;

function TServiceCalculator.Add(n1, n2: integer): integer;
begin
  result := n1+n2;
end;

And you expose it:

Server.ServiceRegister(TServiceCalculator,[TypeInfo(ICalculator)],sicShared);

 

On process A, you can now call the above interface served by process B:

Client.ServiceRegister([TypeInfo(ICalculator)],sicShared);

var I: ICalculator;
begin
  I := Client.Service<ICalculator>;
  if I<>nil then
    result := I.Add(10,20);
end;

More details: https://synopse.info/files/html/Synopse mORMot Framework SAD 1.18.html#TITLE_415

 

Sample code:

https://github.com/synopse/mORMot/tree/master/SQLite3/Samples/14 - Interface based services

 

It's even simpler if you use the so-called "method-based service".

 

Hope it helps.

Share this post


Link to post

I thought that is only Win/Linux (server). I need to have IPC on macOS, communicating between macOS apps.

Share this post


Link to post
2 hours ago, softtouch said:

I thought that is only Win/Linux (server). I need to have IPC on macOS, communicating between macOS apps.

Indy runs on many operating systems including Linux. It should also run on macOS.

If you get an "error #5", you may find the cause by debugging, to find the location in your application and the actual operation it tries to perform.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×