示例#1
0
 public static void closeConnection() {
   if (connection != null && connection.isConnected()) {
     cm.removeChatListener(chatlistener);
     connection.removeConnectionListener(connectionListener);
     if (connection.isConnected()) connection.disconnect();
     connection = null;
   }
   Log.i("XmppConnection", "關閉連接");
 }
示例#2
0
  public static XMPPTCPConnection getConnection() {

    if (connection != null) {
      return connection;
    }
    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setServiceName("bbxiaoqu");
    builder.setHost(DemoApplication.getInstance().xmpphost);
    builder.setPort(DemoApplication.getInstance().xmppport);
    builder.setCompressionEnabled(false);
    builder.setDebuggerEnabled(false);
    builder.setSendPresence(true);
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

    connection = new XMPPTCPConnection(builder.build());
    connectionListener = new ViConnectionListener(mContext);
    connection.addConnectionListener(connectionListener);

    cm = ChatManager.getInstanceFor(connection);

    chatlistener = ChatListener.getInstance(mContext);
    cm.addChatListener(chatlistener);

    return connection;
  }
示例#3
0
  public static void login() {
    XMPPTCPConnection connection = XmppTool.getInstance(mContext).getConnection();
    try {
      connection.connect();
    } catch (SmackException e) {
      // e.printStackTrace();
    } catch (IOException e) {
      // e.printStackTrace();
    } catch (XMPPException e) {
      // e.printStackTrace();
    }
    UserService uService = new UserService(mContext);
    Session mSession = Session.get(mContext);
    try {
      connection.login(mSession.getUid(), mSession.getPassword(), "XMPPTCPConnection");
    } catch (XMPPException e) {
      // e.printStackTrace();
    } catch (SmackException e) {
      // e.printStackTrace();
    } catch (IOException e) {
      // e.printStackTrace();
    }

    if (connection.isConnected() && connection.isAuthenticated()) {
      Presence presence = new Presence(Presence.Type.available);
      try {
        connection.sendStanza(presence);
      } catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
      }
    }
  }
示例#4
0
 public void init() {
   connection = new XMPPTCPConnection(connectionConfig.build());
   ConnectionListener connectionListener = new ConnectionListener(this);
   connection.addConnectionListener(connectionListener);
 }
示例#5
0
 public static void setup(XMPPTCPConnection xMPPTCPConnection, Stanza stanza) {
   xMPPTCPConnection.addRequestAckPredicate(new OnceForThisStanza(xMPPTCPConnection, stanza));
 }