MacroMonkey.com - Home

Automation - Macro - Bot - Scripting system.



IPC System:

Generic, simple “Inter-Process Communication” system for communicating data between an MM instance and another process (typically a service DLL injected into a remote process).

Besides the internal MM component, opposite for the external process side there is a Microsoft C/C++ API library:

MacroMonkeyIPC.h”, and “MacroMonkeyIPC.lib”.


There are two objects in the system a sender and a receiver.

The sender, typically the primary object, is used to send and receive raw data to and from the remote process.

The receiver is a simpler object that receives queued messages from an external process and polled to be read.

In the typical setup there will be one sender per process (and no MM receiver), but there can be multiple of each.


The data communicated can only be a string. Note that Lua strings are not zero terminated strings (like C/C++ strings), but can be considered as a block of arbitrary bytes with a length.

With the string.pack, and string.unpack (see above) raw binary data, like C/C++ structures, can efficiently be exchanged.


Sender:

Open an IPC sender connection.

sndrobj = ipc.Sender(szID, [BufferSize], [Timeout])

szID: IPC connection ID. This needs to be unique and known by both the script and remote sides. Only one connection

is allowed per IPC channel.

BufferSize: Optional internal buffer size, rounded to the nearest page (4096 bytes), default 16384.

Timeout: Optional communicate timeout time (in milliseconds), default 4000.

These arguments must match the remote side as well.

Note: It’s rare that one will need to use other then the BufferSize and Timeout defaults. Only in the case of the user needing to send or receive very large blocks of data, etc.


Methods:

bResult, result = sender:Send(string)    Send a block of raw data (via string), and optionally receive a block from remote process.

bResult = true on success, and result can contain an optional raw data string result.

If bResult = false, then result will be an error string.


idstring = sender:GetID()    Returns ID string for sender.


Receiver:

Open an IPC receiver connection to receive remote messages from another process.

rcvrobj = ipc.Receiver(szID, [BufferSize], [Timeout])

szID: IPC connection ID. This needs to be unique and known by both the script and remote sides. Only one connection

is allowed per IPC channel.

BufferSize: Optional internal buffer size, rounded to the nearest page (4096 bytes), default 16384.

Timeout: Optional communicate timeout time (in milliseconds), default 4000.

These arguments must match the remote side as well.

Note: It’s rare that one will need to use other then the BufferSize and Timeout defaults. Only in the case of the user needing to send or receive very large blocks of data, etc.


Methods:

idstring = receiver:GetID()    Returns ID string for receiver.

table = ipc.Poll()    Poll incoming receive messages

Table format:

.ID = IPC channel ID string.

.Timestamp = Relative time when message was sent.

.Data = string data block


Warning: The internal IPC receive message queue has only space for 2000 maximum.

After that it will wrap around loosing oldest messages.

The events should be polled at least once every few seconds at a minimum to avoid overflow.