Speaking to Processing from Google talk or Jabber
Google Talk is using xmpp, so this works with Jabber and all the other xmpp-supporting instant messegers out there.
It is really easy to do, using the Smack API. Here is how.
- Download the Smack API
- Make a new sketch in Processing
- Add smack.jar and smackx.jar from the Smack API
- Sketch -> Add File…
- smack.jar and smackx.jar are placed in the /code folder in your Processing sketch
- Study the Smack documentation
Here is a working example – Just use your own username/password: (Download the code here: GoggleTalkExample2.zip )
Important password notice: To make this work, your password strength at you google password needs to be Strong. If not, you will get an authentication-error from Google.
/**
Receiving data from Google Talk
Using the Smack API - http://www.igniterealtime.org/projects/smack/index.jsp
Example by Christian Liljedahl, 6. april 2010
Add smack.jar and smackx.jar to your project Sketch -> Add file...
*/
int redColor = 255;
String FromGoogleTalk = "";
// newChat has to be declared global. If not, the MessageListener will time out
after 30 seconds. Processing does this, for some reason.
Chat newChat;
void OpenChatConnection(){
// This is the connection to google talk. If you use jabber, put other stuff in here.
ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
//config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
try {
connection.connect();
}
catch (XMPPException e1) {
}
try {
// This is the username and password of the chat client that is to run within Processing.
// Google password has to be of _strong_ quality to work
connection.login("processing_clientusername@gmail.com", "password");
//connection.login("inside_processing_username@gmail.com", "yourpassword");
}
catch (XMPPException e1) {
// would probably be a good idea to put some user friendly action here.
e1.printStackTrace();
}
// It would be pretty to do some sort of test here, to make sure we are connected.
ChatManager chatmanager = connection.getChatManager();
// Eventhandler, to catch incoming chat events
newChat = chatmanager.createChat("useryouwanttolistento@gmail.com",new MessageListener() {
public void processMessage(Chat chat, Message message) {
// Here you do what you do with the message
FromGoogleTalk = message.getBody();
// Process commands
println(FromGoogleTalk);
}
}
);
}
void setup() {
size(200, 200);
noStroke();
background(0);
OpenChatConnection();
}
void draw() {
fill(redColor,100 ,100);
text(FromGoogleTalk, 15, 30);
}

NICE WORK!
Now we only need a similar XMPP glue component for the web app end and we can have a nice and relaxed conversation with Processing through a web I/F