LightMessaging

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". It is usually used as an API to RocketBootstrap.

Server

Starting the Server

The Callback

voidsome_callback(CFMachPortRefport,LMMessage*request,CFIndexsize,void*info){// get the reply portmach_port_treplyPort=request->head.msgh_remote_port;// sanity checkif(size<sizeof(LMMessage)){LMSendReply(replyPort,NULL,0);LMResponseBufferFree((LMResponseBuffer*)request);return;}// get the data you recievedvoid*data=LMMessageGetData(request);// send some data backconstchar*msg="lol";LMSendReply(replyPort,msg,strlen(msg)+1);// free the response buffer??LMResponseBufferFree((LMResponseBuffer*)request);}

Client

This can be put literally anywhere.

// setup connectionLMConnectionconnection={MACH_PORT_NULL,"net.iphonedevwiki.some.server"};//send messageLMResponseBufferbuffer;constchar*msg="lol wtf";SInt32messageId=0x1111;// this is arbitrary i thinkLMConnectionSendTwoWay(connection,messageId,msg,strlen(msg)+1,&buffer);LMMessage*response=&(buffer.message);// do whatever you want !!!!constchar*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.