Linux interprocess communication

Status
Not open for further replies.

sryan2k1

Ars Legatus Legionis
46,879
Subscriptor++
Hey All,

I've got an embedded Linux system (running a fairly recent 2.6.x Kernel) that we are developing some applications for.

I'm trying to figure out a good way to get data between C applications running on the box, more specifically a one-to-many scenario.

I like the idea of using the networking system (makes it more portable to other systems) and for 1-1 connections UDP packets using the localhost address works great, however I'm not sure what to do when I need multiple receivers on the same system.

For example an application is going to read and parse GPS data from a physical (TTL) serial port and provide that information to any other subsystem/app that wants it, but you can't bind more then one receiver to the same port. UDP is nice since you just sendto() and if something is out there, they get it, and if not they don't. But I'm not sure of the best approach. RAM isn't an issue.


Any ideas?
 

chalex

Ars Legatus Legionis
11,918
Subscriptor++
For example an application is going to read and parse GPS data from a physical (TTL) serial port and provide that information to any other subsystem/app that wants it, but you can't bind more then one receiver to the same port. UDP is nice since you just sendto() and if something is out there, they get it, and if not they don't. But I'm not sure of the best approach. RAM isn't an issue.

The way you do it is by having a daemon that listens on the port and then forks off a new daemon for each incoming connection. Look at how Apache works.

I think in high school we wrote a chat server, so look at something basic like that.
 

levine

Ars Tribunus Militum
1,986
You could roll it yourself with named pipes and a lot of headaches. Or you can use (as job suggests) ZeroMQ, and set up a PUB/SUB architecture between your processes. I use ZeroMQ on a daily basis and highly recommend it.

edit:
a TCP server that fork's off processes for each client?
memory mapped IO using mmap?
The way you do it is by having a daemon that listens on the port and then forks off a new daemon for each incoming connection. Look at how Apache works.
These would all work, in theory. But (to put it lightly) there's a lot of things you need to take into consideration if your final product is going to be at all robust, and a lot of that stuff is nontrivial. If you can leverage other people's experience and knowledge (ie. with ZeroMQ), you'll be much better off.
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
But (to put it lightly) there's a lot of things you need to take into consideration if your final product is going to be at all robust,
A huge advantage of using sockets is that if you ever have to move to a distributed model where everything is not on the same server, you do not have to rewrite all your named-pipe code, you just have to tweak a few things while keeping most of the code intact.
 

Arakageeta

Ars Scholae Palatinae
729
Subscriptor++
Do you want to support both push and pull models? If you only need pull, I like the mmap() solution best. If you only need push, then I believe pipes would be the easiest. Another option for push would be multicast (always overlooked!): it makes sending updates much simpler. Perhaps you could combine the two methods if you need both push and pull (thus clients don't need to send a message to the server to request data).

You might want to take a peak at Linux's dbus, but I don't know enough about it to give a strong endorsement. It may be too much work for a simple application such as yours. (Same goes for CORBA-- overkill.)
 

levine

Ars Tribunus Militum
1,986
Arakageeta":td1nn5mf said:
Do you want to support both push and pull models? If you only need pull, I like the mmap() solution best. If you only need push, then I believe pipes would be the easiest. Another option for push would be multicast (always overlooked!): it makes sending updates much simpler. Perhaps you could combine the two methods if you need both push and pull (thus clients don't need to send a message to the server to request data).

You might want to take a peak at Linux's dbus, but I don't know enough about it to give a strong endorsement. It may be too much work for a simple application such as yours. (Same goes for CORBA-- overkill.)
mmap, dbus, CORBA? Did I enter a timewarp to 1996 and not realize it?
 

Arakageeta

Ars Scholae Palatinae
729
Subscriptor++
levine":1hwn9b3a said:
Arakageeta":1hwn9b3a said:
Do you want to support both push and pull models? If you only need pull, I like the mmap() solution best. If you only need push, then I believe pipes would be the easiest. Another option for push would be multicast (always overlooked!): it makes sending updates much simpler. Perhaps you could combine the two methods if you need both push and pull (thus clients don't need to send a message to the server to request data).

You might want to take a peak at Linux's dbus, but I don't know enough about it to give a strong endorsement. It may be too much work for a simple application such as yours. (Same goes for CORBA-- overkill.)
mmap, dbus, CORBA? Did I enter a timewarp to 1996 and not realize it?
dbus is hardly that old! As for mmap(), if it's not broke, why fix it? It's still used everywhere. As for CORBA.... yeah. I guess I threw it in there for the sake of completeness.

I notice that ZeroMQ that you suggested appears to wrap several IPC methods others have suggested-- still neat though. It looks like a good way to go.
 
Status
Not open for further replies.