Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

So, you want to communicate?

Use JClaim libraries to write IM-enabled applications

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Numerous methods of inter-client communication are available on the Internet. Perhaps the simplest way is to connect via sockets. Though quick and efficient, this mode of communication has numerous limitations. Clients are required to know how to locate each other's IP addresses, which ultimately results in increased security risk for either computer. In some instances, a direct connection is not available. Further, security algorithms must be implemented in order to avoid prying eyes.

In many ways, email is convenient for inter-client communication, but is quite slow. Due to the pervasiveness of spam, more and more restrictions are being imposed upon email accounts, such as size and number of recipients.

Utilizing instant messaging (IM) promotes fast communication—both direct and indirect. For most clients, direct communication is not a necessity. Despite the fact that some protocols do not allow large messages, relaying substantial correspondences may be expedited as file transfers through IM. Delivery is instant, and most firewalls will pass IM traffic. Essentially, even if a user's primary intent is not to send messages, IM protocols still prove useful in the automation of a P2P environment as they provide a ready platform as well as some inherent anonymity.

Supporting email in your Java application is as simple as including mail.jar in your classpath. Fortunately, you only have to worry about one protocol: SMTP (Simple Mail Transfer Protocol). In the IM world, because of the multitude of different protocols, things are not quite as simple. Nevertheless, we need only one project: JClaim, a set of components for IM communication. It includes not only an interactive client, but also a library of classes and interfaces that together make up a flexible framework that supports AIM (AOL Instant Messager), ICQ, Yahoo, MSN (Microsoft Network), Jabber, and GoogleTalk. Other protocols can be added quickly and easily.

This article shows you how to incorporate IM into your application using JClaim. We will write a bot that responds with the current date and time. A bot is an auto-responder used to automate repetitive tasks and is the simplest use of a communication library that we could think of.

Building the JClaim tree is easy. Source code for JClaim can be found on the JClaim Website, in Subversion. For this article, we will only be concerned with the IM API residing in the java/core directory. Supporting JARs are located in the lib folder at the root of the repository.

If you would like to avoid the steps for building the jar files, simply grab the jar files referenced in Resources, add them to your classpath and proceed to the next section of this article. Please note that many other jar files are needed to use JClaim features not addressed in this article. For that, you should look into how to build the project source tree.

To compile the tree:

  1. Grab a Subversion client you would like to use (Tortoise, IntelliJ, Eclipse (with a plugin), see Resources)
  2. Check out the whole tree into a subfolder
  3. Locate an install Ant
  4. Use ant jar command to compile the tree
  5. Examine the run target to create your own or configure your IDE

Model

The figure below illustrates the object model behind the JClaim communication libraries. Start tracing from the Connection interface to make better sense of it all.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.