TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Feb 2016 |
Maintained by Nevyn Bengtsson, Nevyn Bengtsson.
By Nevyn Bengtsson, 2015-08-09
MeshPipe is an IPC (inter-process communication) library for iOS using UDP networking. It allows multiple running applications on a single iOS device to send arbitrary data to each other. It:
Since it is based on UDP, there are some hard-wired limitations:
Start out by selecting a port, and the maximum number of participating apps.
Each app will try to connect to count
other apps, so don't make this number too
large as it will create a very large number of UDP sockets.
Try somehow to choose a port and range that does not overlap with other apps' usage of UDP or MeshPipe. Perhaps we can coordinate usage on the wiki for this project?
Each app can also identify itself with a name. I suggest using "(appBundleName).(nameOfLibrary)".
_pipe = [[MeshPipe alloc] initWithBasePort:12568 count:8 peerName:name delegate:self];
When other peers have connected, you can talk to them like so:
[peer sendData:[@"Hello" dataUsingEncoding:NSUTF8StringEncoding]];
Implement the delegate method to receive data:
- (void)meshPipe:(MeshPipe*)pipe receivedData:(NSData*)data fromPeer:(MeshPipePeer*)peer
You can broadcast to all peers (i e all other connected apps) by enumerating the connected peers:
for(MeshPipePeer *peer in pipe.peers)
[peer sendData:[@"Hello" dataUsingEncoding:NSUTF8StringEncoding]];
You can KVO on peers
, or if you prefer, implement delegate methods for callbacks
when peers connect/disappear:
- (void)meshPipe:(MeshPipe*)pipe acceptedNewPeer:(MeshPipePeer*)peer
- (void)meshPipe:(MeshPipe *)pipe lostPeer:(MeshPipePeer*)peer withError:(NSError*)error
Note that on disconnection, the errors are in the MeshPipeErrorDomain
domain
and are listed at the bottom of MeshPipe.h.
If you want to shuffle more fun kinds of data around a MeshPipe network, you can use Cerfing, and the attached CerfingMeshPipeTransport.See the Transport target's main.m for a demo.