Code to send message from Python script to FPC's TSimpleIPCServer
Just sharing, in case someone will find the below information useful,
or worthy to add to some wiki or docs anywhere:
I have here a daemon written in FPC that communicates with clients by
very nice TSimpleIPCServer class (in SimpleIPC unit). Of course it's
trivial to send a message to such server from another FPC program (see
fcl-base/examples/ipcclient.pp). Turns out it's also trivial to send
a message from a Python program. Attaching the Python code. You can
probably easily add alternatives for any other programming language to
Note that this is specific to Unix, where SimpleIPC just uses a named
pipe, so it looks just like a writeable file (/tmp/server_name) to any
other process. I don't know how it looks for other OSes.
# Test that you can write from Python to ipcserver named pipe.
# FPC handles messages by very nice and comfortable FPC unit simpleipc.
# See packages/fcl-process/src/unix/simpleipc.inc.
# Message send/received is represented by
# TMsgHeader = Packed record
# Version : Byte; // always MsgVersion = 1
# MsgType : TMessageType; // actually anything, server ignores it,
# // but convention says SendStringMessage sets MsgType = mtString = 1.
# // TMessageType is just LongInt.
# MsgLen : Integer; // length in bytes of following data
# FPC hides this from ipcserver, but in Python program we have to be able
# to encode such thing "by hand".