在Smack 4.1中实例化ConnectionConfiguration

rah*_*hul 2 android xmpp openfire smack

我正在我的Android应用程序中实现聊天功能.所以我已经安装了一个开放式服务器和Smack客户端库,现在我已经编写了一个代码来连接服务器,但是我收到的错误表明ConnectionConfiguration是一个抽象类.所以我不能实现.你能告诉我一下SMACK 4.1中ConnectionConfiguration的实例化吗?

Ale*_*xey 7

尝试使用以下示例:

    XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    config.setUsernameAndPassword(USER_ID+ "@" + DOMAIN, key);
    config.setServiceName(DOMAIN);
    config.setHost(DOMAIN);
    config.setPort(PORT);
    config.setDebuggerEnabled(true);
    config.setSocketFactory(SSLSocketFactory.getDefault());

    mConnection = new XMPPTCPConnection(config.build());
    try {
        mConnection.connect();
    } catch (SmackException | IOException | XMPPException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)