Guest User

Untitled

a guest
Feb 20th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. /**
  2. *
  3. */
  4. package se.redsox;
  5.  
  6. import org.jivesoftware.smack.Connection;
  7. import org.jivesoftware.smack.ConnectionConfiguration;
  8. import org.jivesoftware.smack.XMPPConnection;
  9. import org.jivesoftware.smack.XMPPException;
  10. import org.jivesoftware.smack.Roster;
  11. import org.jivesoftware.smack.RosterEntry;
  12. import org.jivesoftware.smack.Chat;
  13. import org.jivesoftware.smack.ChatManager;
  14. import org.jivesoftware.smack.MessageListener;
  15. import org.jivesoftware.smack.packet.Message;
  16. import org.jivesoftware.smack.SmackConfiguration;
  17.  
  18. /**
  19. * @author pjn
  20. *
  21. */
  22. public class Smacker {
  23.  
  24. /**
  25. * @param args
  26. */
  27. public static void main(String[] args) {
  28.  
  29. SmackConfiguration.setLocalSocks5ProxyEnabled(false);
  30.  
  31. System.out.println("Starting session...");
  32. try {
  33. // Create a connection to the igniterealtime.org XMPP server.
  34. String server = "brooklyn.local";
  35. int port = 5222;
  36. //ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
  37. ConnectionConfiguration config = new ConnectionConfiguration(server, port);
  38. Connection con = new XMPPConnection(config);
  39. System.out.println("Connecting to : " + con.getHost() + ":" + con.getPort());
  40. // Connect to the server
  41. con.connect();
  42. // Most servers require you to login before performing other tasks.
  43. String username = "pjn";
  44. String password = "zap123";
  45. // will receive the message sent.
  46. String receiver = "pjn";
  47. con.login(username, password);
  48. ChatManager cm = con.getChatManager();
  49. Chat chat = cm.createChat(receiver, new MessageListener() {
  50. public void processMessage(Chat chat, Message message) {
  51. System.out.println("Received message: " + message);
  52. }
  53. });
  54.  
  55. chat.sendMessage("Smack> Message sent via API.");
  56.  
  57. //Thread.currentThread();
  58. Thread.sleep(10000);
  59. // Disconnect from the server
  60. con.disconnect();
  61. }
  62. catch (XMPPException e) {
  63. e.printStackTrace();
  64. }
  65.  
  66. catch (InterruptedException e) {
  67. e.printStackTrace();
  68. }
  69. System.out.println("Ended session...");
  70. }
  71.  
  72. }
Add Comment
Please, Sign In to add comment