Difference between revisions of "LightMessaging"

From iPhone Development Wiki
Jump to: navigation, search
m (Working, Digestible Example Code)
(Working, Digestible Example Code)
Line 76: Line 76:
=== Working, Digestible Example Code ===
=== Working, Digestible Example Code ===
* [https://github.com/r-plus/libcanopenurl/blob/master/LCCanOpenURL.x libcanopenurl]
* [https://github.com/r-plus/libcanopenurl/blob/master/LCCanOpenURL.x libcanopenurl] (client and server are in the same file)
* Lucy ([https://github.com/rweichler/lucy/blob/master/client/liblucy.c client], [https://github.com/rweichler/lucy/blob/master/server/springboard.m server])
* Lucy ([https://github.com/rweichler/lucy/blob/master/client/liblucy.c client], [https://github.com/rweichler/lucy/blob/master/server/springboard.m server])

Revision as of 01:27, 3 August 2016

LightMessaging is a sexy header-only IPC framework by the grate god Ryan Petrich. According to its GitHub page, it is a "simple low-level replacement for CFMessagePort".

Why should I use this?

  • Ryan Petrich.
  • Everyone else is using it.


It is recommended that this is only done in SpringBoard.

Starting the Server

LMStartService("net.iphonedevwiki.some.server", CFRunLoopGetCurrent(), (CFMachPortCallBack)some_callback);

The Callback

void some_callback(CFMachPortRef port,
                        LMMessage *request,
                        CFIndex size,
                        void *info)
    // get the reply port
    mach_port_t replyPort = request->head.msgh_remote_port;
    // sanity check
    if(size < sizeof(LMMessage)) {
        LMSendReply(replyPort, NULL, 0);
        LMResponseBufferFree((LMResponseBuffer *)request);
    // get the data you recieved
    void *data = LMMessageGetData(request);

    // send some data back
    const char *msg = "lol";
    LMSendReply(replyPort, msg, strlen(msg) + 1);

    // free the response buffer??
    LMResponseBufferFree((LMResponseBuffer *)request);


This can be put literally anywhere.

// setup connection
LMConnection connection = {

//send message
LMResponseBuffer buffer;
const char *msg = "lol wtf";
SInt32 messageId = 0x1111; // this is arbitrary i think
LMConnectionSendTwoWay(connection, messageId, msg, strlen(msg) + 1, &buffer);
LMMessage *response = &(buffer.message);

// do whatever you want !!!!
const char *data = LMMessageGetData(response);

ConsumeInteger / ConsumePropertyList / etc

There are some cool helper functions for if you want to send Images / PropertyLists / etc instead of just strings. Look at the header file or other examples to see how to use them.


Working, Digestible Example Code

From rpetrich himself