Oh the weather outside is frightful

I really would have like to finish part 2 of IM Integration with XMPP4r before Christmas but I wasn’t able to make it, sorry. I didn’t want to rush it neither and it would have been stupid to do so.
I just want to wish you a merry Christmas. Have a good time with your loved ones. That’s it! I’m ending this post by showing you my 2 favorite Christmas songs. What are yours?
#1 : This Jingle Bells interpretation by Frank Sinatra is simply incredible. Too bad it’s just the beginning of the song… could not find the full version on youtube. I love those J-I-N-G-L-E BELLS, Oh!

#2 : Let it snow by Frank Sinatra

Tell me where my things are, Mrs. Pratt!

I’m proud to present you my latest project : Mrs. Pratt !

Who is Mrs. Pratt?

Mrs. Pratt is a super woman who will help you remember where you things are!

The idea is simple : You tell Mrs. Pratt whenever you lend something to someone. Say for example that you lent your Bing Crosby Christmas album to Georges, you just have to tell Mrs. Pratt about it, like that :

Developed with RoR and uses xmpp4r for IM integration

Once again, this is a project I created with RubyOnRails. I also used the ruby library Xmpp4r which is the object of an ongoing serie of articles on RubyFleebie.

There is also a really simple API available for developers who would like to integrate Mrs. Pratt with their own appliaction.

That’s it! I hope you will like the idea. If you do, please be kind enough to send me your comments/suggestions/rants about the project at [email protected]

IM Integration With XMPP4r

Some of you might be aware that I worked on a project called TimmyOnTime. It is a product that allow you to track your time using your Instant Messaging application only. How we did it exactly? Where’s the code? Nice try! But I won’t tell you… however I will help you getting start with XMPP4r (XMPP For Ruby).
This will be a multipart article. You know, it wouldn’t be my style to talk about XMPP4R without talking about XMPP first. One thing at a time! So, this article is just about XMPP… no XMPP4r.

What is XMPP?

The eXtensible Messaging and Presence Protocol (aka as Jabber) is a protocol to exchange messages between 2 entities. Those messages are transmitted over the wire in the XML format.

Decentralized

Unlike MSN and AIM which are proprietary protocols/technologies, no one owns Jabber. You don’t log on THE Jabber Network like you log on MSN. When you use a Jabber client like Pidgin, Google Talk (Technically, GTalk is not a jabber client… but we won’t go into this) or Gajim, you log on SOME Jabber server. You could even setup your own Jabber server. It doesn’t matter because these servers can talk to each other (but are not forced to… private jabber servers are pretty common). Server-to-server communication is in fact one of the primary asset of the Jabber architecture.
Say I’m using Pidgin and that my Jabber Account is located on www.jabjab.de (it’s just one of the many public jabber servers), this will probably give me a JID (Jabber identifier) like [email protected]/home.

JID?

So suppose my JID is indeed [email protected]/home. The first part of the JID is “frank”, which identifies the NODE or, in other words, identifies a person. The second part of the JID is “jabjab.de” and it identifies the SERVER to call in order to send messages to “frank”. The last part of the JID is “/home” and it identifies the RESOURCE. Think of resources as “multiple identities”. Frank could in fact load 2 instances of Pidgin at the same time (one IM at home and the other at work) so it would result in two different JID, respectively “[email protected]/home” and “[email protected]/work”.

The XML messages : Streams and Stanzas

Like I said, Jabber messages are encoded in the XML format. A stream is a container to exchange information between a client and a server (e.g. between pidgin and jabjab.de). It simply is a XML element called “stream” that starts with <stream> and ends with </stream>. Within the stream element, both the client and the server can exchange other kind of XML messages (called stanzas). The communication is terminated when one of the 2 sides sends the closing </stream> element to the other. For example, if i close Pidgin, Pidgin will send the </stream> to jabjab.de and the session will be over.
One important thing to understand is that the stream DOES NOT exist between USER A and USER B… it exists between YOUR CLIENT (e.g. Pidgin) and the SERVER where YOUR Jabber account is located (e.g. jabjab.de).
Stanzas are special kind of XML messages that are sent within a stream element. The 3 most common stanzas are :

  1. Message
  2. Presence
  3. IQ

A message stanza is used when USER A ([email protected]/home) sends a message to USER B ([email protected]/home)… you know, like “Frank… are you there?”. it may looks like :

<stream>
<message to=’[email protected]/home’>
<body>Frank… are you there?</body>
</message>


</stream> <!- – Well… the closing stream element is not there if the session is still active! Everything happens at real time after all – ->
Let’s take a second to think about what happens exactly when a message is sent between 2 entities from 2 different servers. USER A sends the message through his IM client. The message stanza will be sent to USER A server, which is someserver.com. someserver.com will see that the message is intended to USER B from someotherserver.com so it will send the message there. someotherserver.com will finally send the message stanza to USER B (considering that USER B and someotherserver.com have established a session together thru a stream element). Yay!
A presence stanza is sent when the status of a user changes (Idle, Offline, Available, Do not disturb, etc).
IQ (Info / Query) stanzas are more general purpose messages. It can be used when USER A wants to know something about USER B but that it cannot be achieved by sending a message or a presence stanza. For example, if USER A choose the “get info” option for USER B, an IQ stanza will be sent to USER B, and USER B will answer to USER A with another IQ stanza containing the information that USER A asked for.
That’s it for part 1… in the next part I think we’ll be ready to dive into XMPP4r. There is also one point that I didn’t address about XMPP… and this is the Authentication process (SASL or TLS). So, next part should talk about this as well.