启用流管理 xmpp 连接 smack 4.1

Enable stream management xmpp connection smack 4.1

我尝试通过这段代码启用流管理(XEP-0198)

XMPPTCPConnectionConfiguration connConfig = XMPPTCPConnectionConfiguration.builder().setHost(HOST)
            .setPort(PORT).setDebuggerEnabled(true).setSecurityMode(SecurityMode.disabled)
            .setUsernameAndPassword(USERNAME, PASSWORD).setServiceName(SERVICE).build();

    XMPPTCPConnectionconnection = new XMPPTCPConnection(connConfig);

        connection.setPacketReplyTimeout(TIME_OUT);
        connection.connect();
        connection.login();
        connection.setUseStreamManagement(true);

但后来当我检查流管理时它 returns 错误。

我想你需要在连接到 xmpp 之前设置流管理。

XMPPTCPConnectionConfiguration connConfig = XMPPTCPConnectionConfiguration.builder().setHost(HOST)
        .setPort(PORT).setDebuggerEnabled(true).setSecurityMode(SecurityMode.disabled)
        .setUsernameAndPassword(USERNAME, PASSWORD).setServiceName(SERVICE).build();

XMPPTCPConnectionconnection = new XMPPTCPConnection(connConfig);

    connection.setUseStreamManagement(true);
    connection.setPacketReplyTimeout(TIME_OUT);
    connection.connect();
    connection.login();