XMPP ("Extensible Messaging and Presence Protocol" aka Jabber) is a popular protocol which is very useful in a variety of situations and programs. It's a lot more than just instant messaging! For example, the presence notifications alone could be useful to help clients discover remote servers or vice-versa. We use XMPP in Mojo to help clients create direct TCP connections. There's a lot of potential for use outside the narrow scope of IM.
In terms of development, there are a handful of XMPP libraries available:
List on Jabber.org
List on Wikipedia
However, you'll notice neither list includes an Objective-C/Cocoa implementation. This doesn't make it impossible to use one of the listed libraries. One can always use a C or C++ library. Although I won't promise it won't give you headaches or that you won't regret it.
There has been work on XMPP in Cocoa:
JabberFox is an old Jabber client for Mac OS X. Written in Cocoa, but hasn't been updated since early 2002.
Colloquy is a Mac chat client which is still in development. It uses the "acid" library, originally written back in 2003 (I think). Browsing their subversion library online, it looks like the acid library was copied from Fire and has received only minor changes.
XMPPFramework - I got really excited when I first stumbled upon this page. But then my hopes sank when I realized it was never released, and hasn't been touched since early 2007. For all I know, they may have only written the interface and not a single line of implementation. :(
Reading over the XMPP code from Colloquy, I was very impressed. It had a lot of good stuff, although it showed it's age a bit. For example, it uses it's own XMLElement class. This is no longer needed as 10.4 introduced it's own set of XML classes such as NSXMLElement, NSXMLNode, etc. It also uses the expat parser. Certainly not a bad parser (I actually wrote a Cocoa wrapper for it back in the day). But I wonder if it would have been used today as 10.3 introduced NSXMLParser, and 10.4 added XQuery and XPath stuff.
So I got to thinking about what it might take to write the basic code for a Cocoa XMPP framework, and I guessed that it might not be too difficult. It tured out to be a little harder than I thought, but not impossible. What I'm releasing is certainly not a full framework. But it could be used as the basis/beginning of one. It's pretty much just a single class at this point: XMPPStream. It has the basics down:
- Connect to a host
- Support for SSL and STARTTLS
So at this point you can actually use the available code to login to Google Talk, and chat with your friends. All you have to do is instruct the class to connect to the proper server, authenticate, and handle the delegate messages:
- (void)xmppStream:(XMPPStream *)xs didReceiveIQ:(NSXMLElement *)iq;
- (void)xmppStream:(XMPPStream *)xs didReceiveMessage:(NSXMLElement *)message;
- (void)xmppStream:(XMPPStream *)xs didReceivePresence:(NSXMLElement *)presence;
Download the code
Remember: I'm not writing a chat client, and that's not the purpose of this source code. The GUI exists solely as testing for the XMPP library.
What still needs to be done:
Write nice little wrapper classes (that extend NSXMLElement) for IQ, Message and Presence elements. Something like XMPPIQElement, XMPPMessageElement, and XMPPPresenceElement. These would ideally have convenient methods for accessing common information.
Write an XMPPClient, which automatically handles fetching and updating the roster, and offers convenient methods for adding/removing users.
Write XMPPRoster class.
I've more or less implemented much of the above. I just haven't written out a nice API for it.
Perhaps this code will be useful. Perhaps somebody will use it to help make a full framework. Perhaps they'll modify somebody else's code. Perhaps they'll write their own. I really don't care how it gets done, the important thing is that Cocoa programmers get their own open source XMPP library.