Как правильно включить управление потоком в smack 4.1.1?

У меня есть поиск для каждого метода, используемого для включения управления потоками в smack, и ничего не работает для меня

Эта функция isSmAvailable() всегда возвращает false, я использую просодию в качестве сервера XMPP, на котором smacks[mod_smacks] установлен и включен ниже - мой код

XMPPTCPConnectionConfiguration.Builder configureBuilder = XMPPTCPConnectionConfiguration.builder();
configureBuilder.setServiceName(Config.XMPP_HOST);
configureBuilder.setHost(HOST);
//configureBuilder.allowEmptyOrNullUsernames();
configureBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);


    //configureBuilder.setDebuggerEnabled(true);
    SmackConfiguration.DEBUG = true;
    xmppConnection = new XMPPTCPConnection(configureBuilder.build());
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);




    XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
    //PingManager
    xmppConnection.setUseStreamManagement(true);
    xmppConnection.setUseStreamManagementResumption(true);

    ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(xmppConnection);
    reconnectionManager.enableAutomaticReconnection();


    try {
      MyLog.w("Connecting to xmpp server");
       xmppConnection.setPacketReplyTimeout(100000);
       xmppConnection.connect();
       //xmppConnection.sendSmAcknowledgement();


       if (xmppConnection.isSmEnabled()) {
      MyLog.w("stream M is enabled");
       } else {
      MyLog.w("stream M is not enabled");
       }


       if (xmppConnection.isSmAvailable()) {
      MyLog.w("stream M available");
       } else {
      MyLog.w("stream M is not available");
       }

       //xmppConnection.
       xmppConnection.addConnectionListener(new ConnectionListener() {
       @Override
       public void connected(XMPPConnection xmppConnection) {
       //logger.warning("Connected to server successfully");
       MyLog.w("Connected to server");
       }

       @Override
       public void authenticated(XMPPConnection xmppConnect, boolean b) {
       //logger.warning("Nice it is authenticated too");
       MyLog.w("Finally logged into the server");

       }

       @Override
       public void connectionClosed() {
       //logger.warning("Connected to server failed");
       }

       @Override
       public void connectionClosedOnError(Exception e) {
       //logger.warning(e.getMessage());
       MyLog.w("Connection close on error" + e.getMessage());
       }

       @Override
       public void reconnectionSuccessful() {
       //I think here we need to relogin the user
       MyLog.w("Reconnected successfully ....thanks to RC");
       }

       @Override
       public void reconnectingIn(int i) {

      }

       @Override
       public void reconnectionFailed(Exception e) {
      MyLog.w("Reconnection Failed " + e.getMessage());
       }
      });
    } catch (Exception e) {
      MyLog.w("connected-error" + e.getMessage());
    }

Я попытался добавить streamFeature для управления потоком с помощью

xmppConnection.addStreamFeature(), но он говорит мне, что функция является частной

а также через ProviderManager.addStreamFeature (элемент, пространство имен, поставщик) также не работает

Можете ли вы помочь мне разобраться в этом, или здесь что-то не так?

Спасибо

2 ответа

Проверьте ваш файл конфигурации ejabbered для управления потоком включен или нет.

stream_management: true
resend_on_timeout: true
resume_timeout: 300

В коде Android вы просто добавляете в строку ниже, чтобы включить управление потоками в вашем приложении.

 static{
    XMPPTCPConnection.setUseStreamManagementDefault(true);
    XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
}

Этот кусок кода работает для меня, поскольку ejabbered на стороне сервера--

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();
Другие вопросы по тегам