Skip to content

Instantly share code, notes, and snippets.

@dunithd
Created November 1, 2010 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunithd/657977 to your computer and use it in GitHub Desktop.
Save dunithd/657977 to your computer and use it in GitHub Desktop.
Jabber client that connects to GTalk and sends a message
package com.dunithd.jabber;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Message;
import java.util.Collection;
public class JabberClient {
public static void main(String[] args) {
SASLAuthentication.supportSASLMechanism("PLAIN");
ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222,"gmail.com");
config.setSASLAuthenticationEnabled(false);
XMPPConnection connection = new XMPPConnection(config);
try {
connection.connect();
connection.login("dunithd", "123456");
System.out.println("Logged in to Jabber...");
/*Roster roster = connection.getRoster();
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
System.out.println(entry.getUser());
} */
Message msg = new Message("arunsambhanthan@gmail.com", Message.Type.chat);
msg.setBody("Hi! this is a test message sent from my chatbot. Please ignore this. - Dunith Dhanushka");
connection.sendPacket(msg);
System.out.println("Message sent!");
} catch (XMPPException e) {
e.printStackTrace();
}
connection.disconnect();
System.out.println("Disconnected from Jabbber...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment