Dev:Unix sockets

Unix sockets are a low-level way of achieving inter-process communication on Unix systems. It isn't really used in iOS, as most other forms of IPC are built on top of Mach ports. However iOS is a unix system so it also includes Unix sockets, which can be useful in certain scenarios.

For more/better reading material, check out beej's Unix socket guide or his excellent network programming guide.

Pros

 * No dependencies
 * Extremely portable
 * Less overhead
 * "Easier" to bypass sandbox restrictions (more on this later)

Cons

 * API is in C instead of Objective-C
 * Not "the Apple way"
 * Takes more work to properly set up

If this is your first time doing IPC, it's probably better to use another method such as CPDistributedMessagingCenter or LightMessaging, which are more straightforward. Unix sockets should only really be used if you've used another IPC method and have found it lacking or restrictive.

Server
You should run  in a background thread, otherwise it will block.

To test, run the command  which will give you a REPL.

Pitfalls of this example
There are a few issues with this example.

First off, the entire server logic is under one thread. That means only one client can connect at a time. If another client tries to connect, it will hang until the first one disconnects. This can be fixed by putting various parts of the server logic under a, or pthread.

The other issue is that it doesn't handle messages that exceed 4096 characters. To mitigate this, it's best to decide on some sort of "separator" string between messages for your protocol ( works well with netcat), and then just do the processing only once you hit that separator.

Bypassing sandbox with inet sockets
In iOS 10, daemons/processes with the "seatbelt" entitlement (e.g. mediaserverd) don't allow you to create or connect to unix domain sockets anymore. :( This is also appears to be an issue with creating Mach ports. Sandboxed processes can still connect to external Mach ports, thanks to RocketBootstrap.

Luckily for us, there is still a workaround: local internet sockets. The key difference with these is that they're not actual internet sockets. The way these will be set up is that they can only be accessed from localhost, so essentially it poses the same security risk as any other IPC method.

But seriously, don't use this method unless you absolutely have to. Using regular unix domain sockets is much, much better than this approach, since you can tie the socket to a file descriptor instead of a port. There are unlimited potential file descriptors, and only a finite number of available ports. Don't reserve a port unless you absolutely have to.

Code
Basically, all you'd have to change is the socket setup:

Choosing a port
The huge pitfall of this approach is having to pick a port. You'll have to pick one between 1024-65535, and is not in Wikipedia's list of TCP port numbers and also not in the list of reserved ports below. Naturally, there is a very real chance that the port you pick will conflict with another service, so choose wisely. Typically something above 10000 and below 50000 will be unlikely to conflict with anything.

List of reserved ports on jailbroken iOS

 * 787: cycript
 * 43333: AudioSnapshotServer
 * 27724: EQE