Recommended way of IPC in Rust

I am building a server application (targeting Unix-like systems) that will receive payloads from clients only on the same machine. Clients will send a request and get a response back with possibility of sending a subsequent request based on what server responded.

What's the best/recommended mechanism to do this? I have been playing around with Unix-domain sockets but I have seen projects that actually use a local web server to receive http requests.
If I am not mistaking, racer uses stdin/command line arguments to achieve something similar.

In my case speed & latency are important so that's why I've been tinkering with sockets.

What's your preferred way of doing this in you Rust projects?

There is some community around GRPC in rust for IPC. Beware that some of them are nightly only.
https://crates.io/search?q=grpc

I have used Unix pipes for this purpose. If your server starts the clients, it can hand each one an anonymous pipe. Otherwise, you can use named pipes.

yea, have to used named pipes since server cant do that.
have you been able to run a Rust program in background as a daemon and when another application tries to launch it again we just send the input arguments to the background process and force it to process them instead of relaunching a new copy of it?

I've had a lot of success with using named pipes and bincode.

Here's an example of using bincode and named pipes: Playground.

1 Like

oh, that's a pretty complete example. Thank you!

Have you had any issues with names pipes? how's the performance?

FWIW, I think making a crate out of that would be useful. Bonus points if It transparently supports named pipes on windows.

In Habitat, we use https://github.com/habitat-sh/ipc-channel, which is a fork of https://github.com/servo/ipc-channel (because we need a particular branch with windows support which has never made it back into master). If you only need unix support, you should be able to use the servo crate directly.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.