snej / MYNetwork

Mooseyard Networking library: Cocoa utilities, including a generic TCP server/client, plus the reference implementation of the message-oriented BLIP protocol. (This is a mirror of the Mercurial repository at https://bitbucket.org/snej/mynetwork)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MYNetwork: Mooseyard Networking Library, With BLIP Protocol Implementation

By Jens Alfke

Introduction

MYNetwork is a set of Objective-C networking classes for Cocoa applications on Mac OS X or iOS. 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:
  • IPAddress, an abstraction for IPv4 addresses
  • PortMapper, a way to make services on a computer behind a NAT router available to computers outside
  • Higher-level Bonjour APIs like BonjourBrowser and BonjourService.

(Details available in the API documentation.)

MYNetwork has been publicly available since May 2008. It's been used in several shipping Mac and iOS applications by multiple developers.

“An awesome network library ... It made moving pages from VoodooPad to the the iPhone over the network completely painless. A++ would recommend again.” *
--Gus Mueller, Flying Meat Software

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!

What's BLIP?

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.

You can read a more detailed overview of BLIP, or examine the protocol specification.

(Unlike the other Mac/iPhone-specific code here, BLIP comes with a platform-independent Python implementation as well.)

Getting Started

Are you sold already? Then please read the Setup instructions. MYNetwork uses the separate MYUtilities library (see Git and Mercurial repos), 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.

License

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.

About

Mooseyard Networking library: Cocoa utilities, including a generic TCP server/client, plus the reference implementation of the message-oriented BLIP protocol. (This is a mirror of the Mercurial repository at https://bitbucket.org/snej/mynetwork)


Languages

Language:Objective-C 92.0%Language:Python 7.8%Language:C 0.2%