Пример #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;
  }