Programmatic IM Generation

2005-12-16 / All Blog posts

I thought it would be fun to create a live code example using Zamples that would generate an IM message. The following Java code example uses Jive Software's Smack library to send a message to a Jabber user with a Gaim client. You will need to put real values in for from, password and to before a message will be sent. BTW, if the userid and password are wrong, you'll get a really odd error message; since the program fragment automatically compiles and runs after you click on the 'Run It!' button, the error message will appear on the right. Once you provide the to and from user ids and password and rerun the code fragment, a message will be sent. I tested this by sending myself a message (from and to were the same.)

XMPPConnection connection = new XMPPConnection("jabber.org");
connection.login("from", "password");
connection.createChat("to@jabber.org/Gaim").sendMessage("Howdy!");

comments powered by Disqus