【问题标题】:What is the proper way of enabling Stream Management in smack 4.1.1在 smack 4.1.1 中启用流管理的正确方法是什么
【发布时间】:2015-09-07 23:59:29
【问题描述】:

我已经搜索了所有用于在 smack 中启用流管理的方法,但没有什么对我有用

这个函数 isSmAvailable() 总是返回 false,我使用 prosody 作为 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(element, namespace, provider) 也不起作用

你能帮我解决这个问题吗,否则这里有问题

谢谢

【问题讨论】:

标签: xmpp smack stream-management


【解决方案1】:

这段代码对我在服务器端进行了 ejabbered 有效--

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

XMPPTCPConnection connection = new XMPPTCPConnection(connConfig);

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

【讨论】:

    【解决方案2】:

    检查您的 ejabbered 配置文件是否启用了流管理。

    stream_management: true
    resend_on_timeout: true
    resume_timeout: 300
    

    在 android 代码中,您只需添加到下一行即可在您的应用中启用流管理。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 2018-10-30
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      相关资源
      最近更新 更多