XMPP Development in Ruby


Recently I wasted a day and half in debugging an XMPP-based service I’m working on. As is usual, the real reason I lost so much time was because I was totally unfamiliar with the terrain. I should have spent an hour or two on XMPP basics before I waded into this unfamiliar territory.

If you’re just starting on XMPP development with Ruby, here are some tips and resources that you might find useful.

One client at a time
For each account, there should only be one XMPP client logged in at any time. If client A is already logged in, and then client B logs in, client A will be disconnected and will stop receiving notifications. Just like in Yahoo! Messenger: when you login from a second client, the first client will be disconnected. It’s so basic, but I managed to waste the better part of a day on debugging perfectly working code before I realized that this was what’s going on in my system.

Use switchboard for testing
When debugging network applications, you want to make sure that the application is indeed the problem and not the network. For web applications, you use curl for testing. switchboard aims to be the curl for XMPP development. curl is a command-line (hence scriptable!) http client; XMPP is a command-line XMPP client.

github page: http://github.com/mojodna/switchboard/tree
command-line usage: http://mojodna.net/2009/07/16/switchboard-curl-for-xmpp.html

Useful Resources
If you’re going to do XMPP development in plain Ruby, there’s a peepcode screencast that you might find useful. It might be a bit dated, though, and most likely there are higher-level libraries that you can use.

In my case, I was working on harvesting blog entries from Superfeedr, so I use the Superfeedr gem, superfeedr-ruby. An alternative is the more streamlined and highly opinionated superfeedr-rb.

Even if you’re not doing Superfeedr work, it’s worth spending the time to study superfeedr-ruby, if only to study how it uses Skates. Skates (formerly Babylon) is a framework for building XMPP applications in Ruby, using EventMachine for handling connections.

,

  1. No comments yet.
(will not be published)
*