Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A way to communicate between applications within linux

I'm currently in the planning stages and could do with help. I'll be using a rasberry pi with various modules plugged into (i2C, USB etc) it, these could be anything such as modules to measure temp, wind speed, direction etc.

The idea is to have each module run its own daemon, this daemon will feed data to the main program upon request or the main program can request the daemon to restart.

All this will be happening on the raspberry pi, not over any sort of network.

My question is what to use to communicate between the main program and the daemons. I've been reading about using dbus, but there are quite a few saying use it as a last resort.

I've been researching for a while and couldn't come up with any other (perhaps easier) ways.

On a side note, the idea of separating them out is because if any modules has issues i can easily restart it without effected the main program.

like image 266
Nathan Avatar asked Jan 29 '26 20:01

Nathan


2 Answers

Look into ZeroMQ. It's sockets on steroids.

It's easy to get started with, and it's perfect for communication between threads in the same process, or between different processes. ZMQ takes away a lot of the headaches that multi-threading and process communication usually means.

Simply use socket.bind in your "main program", and socket.connect in your clients.

In your case it sounds like you might be intereste in the Pub-Sub pattern, where the server subscribes, and clients publish, meaning that it's a one-way communication.

Else, you might be interested in the Req-Router-Dealer-Rep pattern.

http://www.zeromq.org/

like image 144
thnee Avatar answered Feb 01 '26 09:02

thnee


I would just use unix sockets.

The API for Unix domain sockets is similar to that of an Internet socket, but it does not use an underlying network protocol for communication.

I can't link to examples because you didn't give a language, but basically the server will open a socket somewhere on the filesystem (preferably somewhere it has read/write access to, but all other programs only have read access). Then client programs can connect to that socket and send requests just like they would over the internet.

like image 31
Brendan Long Avatar answered Feb 01 '26 09:02

Brendan Long