Created
November 1, 2010 10:55
-
-
Save dunithd/657977 to your computer and use it in GitHub Desktop.
Jabber client that connects to GTalk and sends a message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("[email protected]", 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