How to do inter-process comunication

Looking around, there seems to be few libraries for IPC (inter-process comunication), and none of them is cross-platform (servo/ipc-channels, named pipe for Windows). So what would be the better solution for IPC in Rust ?

What I am interested in is sending/receiving small messages between various executing process of the same application, for monitoring/controlling purposes. I need to be able to do it on both UNIX and Windows.

I got a POC running using only the standard library, with UDP. But this requires to store the localhost port somewhere for future usage, which is not trivial.

2 Likes

I can recommend zmq. There is a Rust binding which covers most things you'll need.

1 Like

It seems to be able to do the job, thank you!

I though it would need a background process, like Redis, but it seems that it is not needed at all.

You can still do IPC using RPC but you would need a server for this, so the processes don't communicate that nicely between them.
Here is an example of that in Cap-n-proto Rust RPC calculator example.

I didn't know about ZeroMQ. I see that you would also need a server with it.

I suggest nanomsg. It is developed by the original author of ZeroMQ and has arguably better API and other characteristics. There are Rust bindings for it, naturally.

Neither ZeroMQ nor nanomsg need a server. ZeroMQ name is misleading - it is not a message broker like ActiveMQ or RabbitMQ, it is an embeddable library.

Neither ZeroMQ nor nanomsg seems to be functional on windows at the moment (both repo have issues about windows support, which are not answered in a definitive way).

Nanomsg seems indeed nice, but is missing a build from source for the C library (in nanomsg-sys). The Makefile build seems necessary for building the C lib, which is a stopper for Windows support. I would like to see it built directly from the build.rs file.