-
-
Save ingyesid/6821010 to your computer and use it in GitHub Desktop.
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 se.redsox; | |
import org.jivesoftware.smack.Connection; | |
import org.jivesoftware.smack.ConnectionConfiguration; | |
import org.jivesoftware.smack.XMPPConnection; | |
import org.jivesoftware.smack.XMPPException; | |
import org.jivesoftware.smack.Roster; | |
import org.jivesoftware.smack.RosterEntry; | |
import org.jivesoftware.smack.Chat; | |
import org.jivesoftware.smack.ChatManager; | |
import org.jivesoftware.smack.MessageListener; | |
import org.jivesoftware.smack.packet.Message; | |
import org.jivesoftware.smack.SmackConfiguration; | |
/** | |
* @author pjn | |
* | |
*/ | |
public class Smacker { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
SmackConfiguration.setLocalSocks5ProxyEnabled(false); | |
System.out.println("Starting session..."); | |
try { | |
// Create a connection to the igniterealtime.org XMPP server. | |
String server = "brooklyn.local"; | |
int port = 5222; | |
//ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); | |
ConnectionConfiguration config = new ConnectionConfiguration(server, port); | |
Connection con = new XMPPConnection(config); | |
System.out.println("Connecting to : " + con.getHost() + ":" + con.getPort()); | |
// Connect to the server | |
con.connect(); | |
// Most servers require you to login before performing other tasks. | |
String username = "pjn"; | |
String password = "zap123"; | |
// will receive the message sent. | |
String receiver = "pjn"; | |
con.login(username, password); | |
ChatManager cm = con.getChatManager(); | |
Chat chat = cm.createChat(receiver, new MessageListener() { | |
public void processMessage(Chat chat, Message message) { | |
System.out.println("Received message: " + message); | |
} | |
}); | |
chat.sendMessage("Smack> Message sent via API."); | |
//Thread.currentThread(); | |
Thread.sleep(10000); | |
// Disconnect from the server | |
con.disconnect(); | |
} | |
catch (XMPPException e) { | |
e.printStackTrace(); | |
} | |
catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Ended session..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment