MYNetwork: Mooseyard Networking Library, With BLIP Protocol Implementation
By Jens Alfke
MYNetwork is a set of Objective-C networking classes for Cocoa applications on Mac OS X or iPhone. It consists of:
- An implementation of BLIP, a lightweight network protocol I've invented as an easy way to send request and response messages between peers. (see BLIPListener, BLIPConnection, BLIPRequest, etc.)
- A generic TCP client/server implementation, useful for implementing your own network protocols; (see TCPListener and TCPConnection)
- Networking utility classes:
(see the API documentation for details.)
Are you sold already? Then please read the Setup instructions. MYNetwork uses the separate MYUtilities library, and you have to do a little bit of one-time configuration to link the projects together, or you'll get weird errors.
What Do the Generic Classes Do?
For some reason the Cocoa frameworks don't include a way to create a TCP server (also known as a listener), only a client connection. To implement a server, you have to use some low-level procedural APIs in CoreFoundation.
Additionally, there are some annoying limitations of the NSStream API, particularly when writing -- NSOutputStream doesn't do any buffering, so you're in charge of spoon-feeding it data at the rate it can handle it. MYNetwork's TCPWriter takes care of that.
There also turns out to be some complicated logic required for implementing time-outs when attempting to connect, and also for closing down a socket connection cleanly. TCPConnection manages that.
BLIP is a message-oriented network protocol that lets the two peers on either end of a TCP socket send request and response messages to each other. It's a generic protocol, in that the requests and responses can contain any kind of data you like. It's somewhat like Jabber/XMPP, and somewhat like HTTP, and a lot like BEEP.
(Unlike the other Mac/iPhone-specific code here, BLIP comes with a platform-independent Python implementation as well.)
License and Disclaimer
MYNetwork is released under a BSD license, which means you can freely use it in open-source or commercial projects, provided you give credit in your documentation or About box.
MYNetwork has been publicly available since May 2008. So far it has been used in one shipping product that I know of -- VoodooPad 4.1, and its companion VP Reader for iPhone. Its developer, Gus Mueller, calls MYNetwork “an awesome network library ... It made moving pages from VoodooPad the the iPhone over the network completely painless. A++ would recommend again.”
If you come across bugs, please tell me about them. If you fix them, I would love to get your fixes and incorporate them. If you add features I would love to know about them, and I will incorporate them if I think they make sense for the project. Thanks!