OS-independent Inter-program communication between Python and C

If you want and need truly OS independent, language independent inter process communication, sockets are probably the best option.

This will allow the two programs to communicate across machines, as well (without code changes).

For reading material, here's a Python Socket Programming How To.


Two possibilities:

  • Use IP sockets. There are some examples in the Python docs. (Really not that hard if you just use the basic read/write stuff.) On the other hand, sockets in C are generally not that simple to use.

  • Create a third application. It launches both applications using subprocess and communicates with both applications through pipes. The chess applications must only be able to read/write to stdin/stdout.

    This has the additional benefit that this application could check if a move is legal. This helps you finding bugs and keeping the games fair.


You can use Protobuf as the inter-program protocol and read/write from a file each one turns.

You may read the intermediate file every n seconds.

Once you have this working, you may move to use sockets, where each program would start a server and wait for connections.

The change should be small, because the protocol would be protobuf already. So, the only place you have to change is where you either read from a socket or from a file.

In either case you'll need an interchange protocol.

edit

Ooops I misread and I thought it was C++.

Anyway, here's the C support for protobuf but is still work in progress work

http://code.google.com/p/protobuf-c/