예제 #1
0
  public boolean openConnection() {
    new AndroidSmackInitializer().initialize();
    try {
      if (null == connection || !connection.isAuthenticated()) {
        // XMPPConnection.DEBUG_ENABLED = true;// ����DEBUGģʽ
        // ��������
        XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
        builder.setHost(SERVER_HOST);
        builder.setServiceName(SERVER_NAME);
        builder.setPort(SERVER_PORT);
        builder.setSendPresence(true);
        builder.setCompressionEnabled(false);
        builder.setSecurityMode(SecurityMode.disabled);

        XMPPTCPConnectionConfiguration config = builder.build();
        connection = new XMPPTCPConnection(config);
        try {
          connection.connect();
        } catch (SmackException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } // ���ӵ�������
        // ���ø���Provider��������ã�����޷��������
        configureConnection(new ProviderManager());
        return true;
      }
    } catch (XMPPException xe) {
      xe.printStackTrace();
      connection = null;
    }
    return false;
  }
예제 #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;
  }