Jabber away with instant
messaging
Tutorial Details:
Jabber away with instant messaging
Jabber away with instant messaging
By: By Jason Kitchen
Add open source, XML-based instant messaging to your Java applications
nstant messaging has enjoyed phenomenal success as a person-to-person communication tool; in some instances, it has supplanted email as the preferred means of online communication. Now, developers are using this technology for application-to-person and application-to-application communication.
Until recently, only a handful of service providers controlled this technology; currently, the popular instant messaging services are communication islands based upon proprietary protocols. Implementers face a difficult decision: support multiple protocols or lock into a single one. Regardless of the choice, the implementer must depend on a server owned by the instant messaging (IM) service provider.
Open protocols can help developers break out of the proprietary trap. The advantages are various: Open protocols encourage development of competing implementations (some of them open source). They encourage widespread adoption of a common protocol, thus preventing the development of communication islands and isolationist approaches to service provisions. In many ways, open protocols made the Internet possible. In the instant messaging realm, open protocols ensure that the interoperability issues of closed systems and protocols won't stunt the growth of IM-based services.
Jabber is an open protocol for instant messaging and presence services. A primary candidate for a common protocol, Jabber has the potential to break the proprietary grip on instant messaging services.
This article will explain how to programmatically send simple Jabber messages and develop a simple notification service based upon open standards and open source APIs and products.
Why Jabber?
The Jabber standards and architecture help create a distributed IM system, reminiscent of the email systems distributed across the Internet, with users connecting to these systems locally. This approach is diametrically opposed to the monolithic system architecture provided by such current service providers as AIM (AOL Instant Messenger), ICQ, MSN (Microsoft Network), and Yahoo, where a single central server or group of centralized servers provide the messaging service. Jabber also resembles the email architecture in other ways: Jabber addresses its end-points (humans, machines, software) with an addressing scheme almost identical to the basic SMTP (Simple Mail Transfer Protocol) scheme. For example, myname@elogex.com is a valid Jabber address, or JID (Jabber ID) in Jabber parlance. For these reasons, Jabber-based systems scale better than existing proprietary systems. Additionally, the protocol allows for gateways to proprietary instant messaging services, should that become necessary.
Various Jabber server implementations, one of which we use in this article, are freely available, which means you no longer need to depend on a third-party IM service provider (third-party Jabber services are also available for those who require third-party hosted services).
Standardization
While discussing the benefits of the Jabber standards, I should mention the IETF (Internet Engineering Task Force) IM standardization efforts. At the time of this writing, the task force's IMPPWG (Instant Messaging and Presence Protocol Working Group) has various RFCs (requests for comments) available, the most important of which are:
RFC 2778: A Model for Presence and Instant Messaging
RFC 2779: Instant Messaging/Presence Protocol Requirements
The IMPPWG has also drafted an Internet standard for a protocol named CPIM (Common Presence and Instant Messaging). The Jabber protocol is also a draft Internet standard, though not part of the IMPPWG effort.
Where does Jabber fit into this standardization effort? According to the Jabber Website , Jabber is "committed to fully support any open real-time messaging protocols, including the IETF protocol"; if and when support for this IETF protocol grows, Jabber aims to position itself as a "leading open source platform" for the IETF protocol. So far, the IETF effort has concentrated mainly on gathering requirements rather than implementation. For the moment, Jabber is the only open instant messaging and presence service protocol with significant open source support. As a result, it has become the de facto standard for open instant messaging.
Another contender to watch out for is Sun Microsystems' Jxta protocol, another XML-based protocol aimed at peer-to-peer (P2P) application developers. Various Jxta implementations are available today; however, due to its relatively recent genesis, Jxta has achieved less traction than Jabber.
See Resources for links to these standards documents and the Jabber project's full statement on IETF support.
Download and install
To get started with Jabber, you first need to download the necessary tools: you need a Jabber server, a Jabber client, and an API that helps manage and hide some of the complexities of socket management, XML parsing, message creation, and so on.
The Jabber server
For the purpose of getting yourself up and running with Jabber, the Jabber server you choose doesn't matter, since they all accept standard Jabber XML and communicate with the end-point application to deliver the payload, which is also standard Jabber XML. jabberd, the original Jabber server implementation, is open source (though not Java based), simple to install and configure, and available on many platforms, including various flavors of Unix, Linux, Windows, and Mac OS X. The JabaServer open source project is also worth mentioning, though at the time of this writing, this Java-based project is not as mature as jabberd. Also, JabaServer installation is less straightforward because you must download, install, and configure a third-party database, plus create the necessary database schema.
For this article's example, I chose jabberd. While both binary and source downloads are available for jabberd, I won't describe how to build a source distribution here. Download the binary distribution, unless you really want to compile your own, from the jabberd homepage . Installation on Windows platforms is relatively easy; the distribution is an .exe ?just execute and follow the installer instructions.
After installation, you should have little or nothing to configure. On Windows 2000, no configuration was required. Just double-click the binary, and the server starts up.
The user agent/client
I decided to use the Exodus client, another open source technology, for this project. I especially like Exodus's debug tab, which allows you to see exactly what XML the client sends and receives. An added bonus: You can type Jabber messages as pure XML and send them to the server. All this proves useful for testing and experimenting with the Jabber protocol and server.
Exodus installation is straightforward. Download the Exodus zip file (I used version 0.6 for this article). Extract the file's contents directly to the directory where you want to install the client. In this release, the file's contents are simply the Exodus binary and a .dll file. For Linux- and Mac-based clients, check out the list of clients at Jabber.org . You can download the Exodus binary from the project's SourceForge homepage .
Jabber API
Probably the best of the current open source Jabber APIs is Muse. Muse provides an easy-to-use high-level API that handles low-level issues such as socket connection and management, as well as conversion of message text to XML for delivery to the Jabber server. This API is not just for Jabber; Muse provides a Java API for abstract access to other services as well, including Yahoo Messenger, ICQ, Napster, AIM, Gnutella, and XML Remote Procedure Call (XML-RPC). The latest release is 0.73a1; however only Jabber, Napster, Gnutella, and XML-RPC are currently represented in the Muse codebase. Other API implementations, such as JabberBeans, are available, but basic Jabber support functions well in release 0.73a1.
Download the Muse API from the Muse homepage .
Send your first Jabber message
To send a Jabber instant message programmatically, you must initialize the Muse Jabber API. Do that by creating an instance of the JabberContext class, then use the context as a parameter to the createSession() method on the Jabber session factory class:
1 // Initialize the Jabber context
2 JabberContext jabberContext = new JabberContext("user", "pass", "localhost");
3
4 // Create an instance of the Jabber session factory
5 Jabber jabber = new Jabber();
6 // Create the new session
7 JabberSession jabberSession = jabber.createSession(jabberContext);
The above example shows the creation of a new context at line 2. The JabberContext stores specific user-related information (username, password, server address) and also contains a unique session identifier when the session is later established using the context. For illustration purposes, I have hardcoded the username, password, and server.
At line 5, a Jabber session factory is created, which we use at line 7 to create a new JabberSession , Muse's main interface into the services offered by the Jabber server. The server's main services are:
Connection services: For connecting to and disconnecting from the Jabber server
User service: For user authentication and registration
Presence service: For receiving presence information from other users/services and broadcasting your own presence
Roster service: Jabber-speak for a buddy list or address book
Chat service: Sends messages of various types?group chat, private messages, headlines, and so on
Server service: Obtains information relating to the services offered by this Jabber server
Client service: Obtains information about other users, such as the last time the user signed in
Now that we have an initialized Jabber session, we can use it to connect to the Jabber server using the connect()
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Jabber away with instant
messaging
View Tutorial: Jabber away with instant
messaging
Related
Tutorials:
Messaging makes its move,
Part 2 - JavaWorld - March 1999
Messaging makes its move,
Part 2 - JavaWorld - March 1999 |
Messaging helps move Java into the
enterprise - JavaWorld January 1999
Messaging helps move Java into the
enterprise - JavaWorld January 1999 |
JMS: An infrastructure for
XML-based business-to-business communication - JavaWorld February
2000
JMS: An infrastructure for
XML-based business-to-business communication - JavaWorld February
2000 |
Which JSP book serves up the best lesson?
Which JSP bookAs for Web servers/databases, just mentioning a server in the book is not sufficient to be listed here. |
Servlet 2.3: New
features exposed - JavaWorld January
2001
Servlet 2.3: New
features exposed - JavaWorld January
2001 |
XML messaging, Part 1 - JavaWorld March 2001
XML messaging, Part 1 - JavaWorld March 2001 |
Deliver
cellular messages with SMS - JavaWorld March 2001
Deliver
cellular messages with SMS - JavaWorld March 2001 |
XML messaging, Part 2 - JavaWorld June
2001
XML messaging, Part 2 - JavaWorld June
2001 |
XML messaging, Part
3
XML messaging, Part
3 |
Jabber away with instant
messaging
Jabber away with instant
messaging |
JForumFusion
About jForumFusion
JForumFusion is a platform independent discussion board program.
|
JMS Messaging Online Resource
JMS Messaging Online Resource
JMS Tutorials
JMS provides a way for Java programs to access an enterprise messaging system, also known as message oriented middleware (MOM). Check out the below tutorials.
|
Jurassic Phoenix - reviving yesterday\'s data
Jurassic Phoenix - reviving yesterday\'s data
Jurassic Phoenix is a simple solution to the problem of evolution of serialized data.
Why use Jurassic Phoenix?
The frustration
Serialization is great for persistence, because it is automatic, dynamic and |
XML Messaging Using JBoss
It\'s common practice to share data using FTP, but an increasingly popular alternative is to use a messaging service. As always, each approach has its own pros and cons, depending on the nature of "what to share," how easy it is to implement the technolog |
Distributed Enterprise Messaging with MantaRay
A very important communication standard in Java is Java Messaging Service (JMS). JMS is a set of Java interfaces and associated semantics that define a way for a Java-based client to access a messaging system. JMS provides a rich, yet simple, set of messa |
Power Messaging, Maps and more...
BuddySpace is an instant messenger with four novel twists: (1) it allows optional maps for geographical & office-plan visualizations in addition to standard 'buddy lists'; (2) it is built on open source Jabber, which makes it interoperable with ICQ, MSN, |
Getting Started with Java Message Service (JMS)
The Java Message Service (JMS) is designed to allow Java applications to use enterprise messaging systems. It makes it easy to develop enterprise applications that asynchronously send and receive business data and events. Learn how to implement it for you |
J2ME Wireless Toolkit 2.2
Now available.This version of the toolkit is fully compatible with the Java Technology for the Wireless Industry (JTWI) specification (JSR 185). |
Your homepage for Cheapest domain name registration, Domain Forwarding Services, Web Designing | Roseindia Domain Regist
Your homepage for Cheapest domain name registration, Domain Forwarding Services, Web Designing | Roseindia Domain Registration
DOMAIN REGISTRATION SERVICES
Roseindia.net is the leading provider of cheapest Domain registration services in India. |

Linux Hosting Plans include "hostsearchbox.php"; ?>
Proxima Web-Hosting
Our basic hosting packages include support for a wide variety of web technologies, backed by instant account management with our Personal Control panel. With our guaranteed |
|
|
|