コード例 #1
0
ファイル: XMPPChatService.java プロジェクト: bearcheese/talk
 @Override
 public void logoutAndDisconnect() {
   if (connection != null) {
     LOGGER.info("Destroying connection...");
     connection.disconnect();
     connection = null;
   }
 }
コード例 #2
0
 @OnClose
 public void onClose(Session session) {
   System.out.println(session.getId() + "------has closed");
   // sess_map.remove(session.getId());
   AbstractXMPPConnection conn = conn_map.get(session.getId());
   conn.disconnect();
   sess_map.remove(session.getId());
   conn_map.remove(session.getId());
 }
コード例 #3
0
ファイル: XMPPUtil.java プロジェクト: ChenQingZhen/XMPPChat
  /** �ر����� */
  public void closeConnection() {
    if (connection != null) {
      // �Ƴ��B�ӱO
      // connection.removeConnectionListener(connectionListener);
      if (connection.isConnected()) connection.disconnect();

      connection = null;
    }
    Log.i("XmppConnection", "�P�]�B��");
  }
コード例 #4
0
  public static void main(String[] args) {
    String username = "******",
        password = "******",
        resource = "viewt",
        serviceName = "openfire-test",
        host = "192.168.1.117";
    host = "127.0.0.1";
    XMPPTCPConnectionConfiguration config =
        XMPPTCPConnectionConfiguration.builder()
            //				  .setUsernameAndPassword(username, password)
            .setServiceName(serviceName)
            .setHost(host)
            .setPort(5222)
            //				  .setDebuggerEnabled(true)
            .setSecurityMode(SecurityMode.disabled)
            .build();
    //		AbstractXMPPConnection conn2 = new XMPPTCPConnection(username,password,"127.0.0.1");
    AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
    try {
      //			SASLAuthentication.registerSASLMechanism(new SASLPlainMechanism());
      conn2.connect();
      //			conn2.login();
      conn2.login(username, password, resource);

      final Roster roster = Roster.getInstanceFor(conn2);

      Set<RosterEntry> set = roster.getEntries();
      Iterator<RosterEntry> iterator = set.iterator();
      while (iterator.hasNext()) {
        System.out.println(iterator.next().getName());
      }
      //			roster.createGroup("family");
      //			roster.createEntry("elijah@openfire-test", "elijah", new String[]{"family"});
      roster.setSubscriptionMode(Roster.SubscriptionMode.reject_all);
      //			roster.
      roster.addRosterListener(
          new RosterListener() {

            public void presenceChanged(Presence presence) {
              System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
            }

            public void entriesUpdated(Collection<String> addresses) {
              System.out.println("Presence changed: entriesUpdated");
            }

            public void entriesDeleted(Collection<String> addresses) {
              System.out.println("Presence changed: entriesDeleted");
            }

            public void entriesAdded(Collection<String> addresses) {
              System.out.println("Presence changed: " + addresses.iterator().next());
              // Roster.SubscriptionMode.reject_all;
            }
          });
    } catch (SmackException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (XMPPException e) {
      e.printStackTrace();
    }

    Scanner sc = new Scanner(System.in);
    String str = null;
    while (!"bye".equals(str = sc.next())) {
      System.out.println(str);
    }
    sc.close();
    conn2.disconnect();
  }