コード例 #1
0
ファイル: XmppTool.java プロジェクト: 594904292/bangbangmang
 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
ファイル: XmppTool.java プロジェクト: 594904292/bangbangmang
  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
ファイル: XmppTool.java プロジェクト: 594904292/bangbangmang
  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));
 }