Browse DevX
Sign up for e-mail newsletters from DevX


Create a Java TOC2 Class to Communicate with AIM : Page 4

Instant messaging is more than a great way to keep in touch: It's a full-fledged business tool and there are plenty of reasons that you might be interested in extending your favorite IM service into a custom chat application. But if you choose AIM, you'll need to be armed with some detailed information about its brand new protocol.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Talking to a Computer
Finally, I will show you a simple example program that makes use of the JavaTOC2 class. This example is contained in the file SystemChat.java. This is a very simple application that demonstrates how to use the class. It can be a starting point for much larger applications.

First, you must modify the run method to include your screen name and password:

public void run() { toc = new JavaTOC2(this); try { toc.login("[Your Screen Name]","[Your Password]"); toc.processTOCEvents(); } catch (IOException e) { e.printStackTrace(); } }

This example program waits for you to chat with it and ask simple questions (see Figure 1). To do this the im method waits for these questions and then sends the answers:

Figure 1. The Chat App: The screen shot shows the basic UI for the chat application built in the article.

public void im(String from, String message) { String str; str = message.toLowerCase(); if( str.indexOf("what time is it")!=-1) { Date d = new Date(); toc.send(from,d.toString()); } else if( str.indexOf("who are you")!=-1) { Date d = new Date(); toc.send(from,System.getProperty("user.name")); } else if( str.indexOf("what are you")!=-1) { Date d = new Date(); toc.send(from,System.getProperty("os.name")+" "+ System.getProperty("os.version")+" "+ System.getProperty("os.arch")); } }

As you can see there are three questions you can ask the system:
  • What time is it?
  • Who are you?
  • What are you?
To answer each of these questions, the program will call on the JDK.

This program demonstrates all of the elements you might use to implement a chat application.

This article did not discuss every feature of TOC2. For more information about buddy lists, media types, and other TOC2 features you can check out the Wikipedia article on the TOC2 command set. This was the source that I used to gather information about the new TOC2 command set.

Future Directions
The source code presented in this article provides a great starting point for creating your own chat applications. Using the JavaTOC2 you can create a chat-enabled Java application in minutes.

If you are going to write software that responds to instant messages, you should be aware that there are several patents that cover this area. As always, you should seek legal advice to determine the extent to which these patents may overlap with your development project.

Additionally, there are very advanced APIs already available for interfacing to chat networks. These APIs also include advanced Natural Language Processing capabilities. One of the oldest and most popular is ConverseAgent. You can even chat with one of its Bots by adding SmarterChild to your AIM buddy list.

Jeff Heaton is an author, college instructor, and consultant. Jeff is the author of four books and over two dozen journal and magazine articles. Jeff maintains a personal website where he publishes information about artificial intelligence, spider/bot programming, and other topics.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date