> What is the right
> way to do this?
I have noticed that all answers so far focused on the lowest possible level, which is a raw communication channel. Sockets can do that. Pipes can do that. Shared memory can do that, too.
But just as you design your program using high-level concepts like objects, classes or containers, instead of raw memory blocks, you might as well raise the level of treatment for interprocess communication. In this analogy, sockets are like raw memory blocks and using sockets is like using malloc. Nobody would suggest using malloc if you need an object-oriented design pattern. It is just not the level of abstraction that is typically needed.
I would suggest going for a message-oriented library, because the level of abstraction is higher. Yes, such libraries very likely use sockets internally, but that's not relevant (just as it is not relevant that a particular design pattern ultimately relies on some malloc calls). What is relevant is that you can send *messages* between programs.
There are many high-level libraries, some of them multi-platform, some of them multi-language.
If you need object-oriented ones, look for CORBA (although some consider it to be outdated) or ICE (
https://zeroc.com/products/ice). If you are not obsessive about object-orientation, then HTTP is also an option, with multiple high-level libraries for both C++ and Python.
As a shameless plug, I will also recommend YAMI4 (
http://www.inspirel.com/yami4), which happens to support both your programming languages.
The advantage of all such libraries is that you can be several steps ahead in your development thanks to the high-level of abstraction that is offered. Otherwise, you might end up reinventing the wheels (and bugs) that were already implemented (and debugged) in those libraries.
Unless, of course, all you need is to send a single flag, once, between two programs. Which is most likely not the case.
--
Maciej Sobczak *
http://www.inspirel.com