【问题标题】:Strophe connection issue with openfire and boshopenfire 和 bosh 的 Strophe 连接问题
【发布时间】:2014-08-15 04:08:05
【问题描述】:

我已使用跨域的示例连接到我的本地 openfire xmpp 服务。 只需更改 BOSH url 以适应我的本地 openfire 服务。

我测试了什么,所以我知道 openfire 本身可以工作。我可以成功连接 Pidgin。

(网站在码头内运行)

(实际的)openfire 安装在 localhost 上运行

提交表单后执行 strophe javascript 表单域:#jid = 'admin@localhost' 表单域:#pass = 'mypassword'

rawInput 和 rawOutput 函数被省略,它们只是记录传输的内容。

var BOSH_SERVICE=http://localhost:8080/xmpp-bosh

function onConnect(status)
{
    if (status == Strophe.Status.CONNECTING) {
    log('Strophe is connecting.');
    } else if (status == Strophe.Status.CONNFAIL) {
    log('Strophe failed to connect.');
    $('#connect').get(0).value = 'connect';
    } else if (status == Strophe.Status.DISCONNECTING) {
    log('Strophe is disconnecting.');
    } else if (status == Strophe.Status.DISCONNECTED) {
    log('Strophe is disconnected.');
    $('#connect').get(0).value = 'connect';
    } else if (status == Strophe.Status.CONNECTED) {
    log('Strophe is connected.');
    connection.disconnect();
    }
}

$(document).ready(function () {
    connection = new Strophe.Connection(BOSH_SERVICE);
    connection.rawInput = rawInput;
    connection.rawOutput = rawOutput;

    $('#connect').bind('click', function () {
    var button = $('#connect').get(0);
    if (button.value == 'connect') {
        button.value = 'disconnect';

        connection.connect($('#jid').get(0).value,
                   $('#pass').get(0).value,
                   onConnect);
    } else {
        button.value = 'connect';
        connection.disconnect();
    }
    });
});

连接示例时出现错误给我以下日志输出:

Strophe is connecting.
SENT: <body rid='4005617322' xmlns='http://jabber.org/protocol/httpbind' to='localhost' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
RECV: <body xmlns='http://jabber.org/protocol/httpbind' authid='' condition='remote-stream-error' inactivity='600' polling='10' requests='2' secure='false' sid='orw55e6kuyZ0F-CFgnxXWMzG' type='terminate' wait='60'><starttls xmlns=''/><mechanisms xmlns=''><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns=''><method>zlib</method></compression><auth xmlns=''/><register xmlns=''/></body>
Strophe failed to connect.
Strophe is disconnected.

任何想法如何克服这个问题? (已经用 pidgin IM 测试过并且可以工作)

【问题讨论】:

    标签: xmpp openfire strophe


    【解决方案1】:

    尝试启用 Strophe 调试以查看更多日志条目

    Strophe.log = function(level, msg) {
        console.log(level + ' : ' + msg);
    };
    

    然后检查 Openfire 的错误、警告甚至信息日志。

    【讨论】:

      【解决方案2】:

      您可以通过让 Openfire 开发人员修复他们的 BOSH 实现来解决这个问题。 (或者也许只是更新您的 Openfire 安装。)

      服务器响应是错误的。

      <body xmlns='http://jabber.org/protocol/httpbind' authid='' condition='remote-stream-error' inactivity='600' polling='10' requests='2' secure='false' sid='orw55e6kuyZ0F-CFgnxXWMzG' type='terminate' wait='60'>
          <starttls xmlns=''/>
          <mechanisms xmlns=''>
              <mechanism>DIGEST-MD5</mechanism>
              <mechanism>PLAIN</mechanism>
              <mechanism>CRAM-MD5</mechanism>
          </mechanisms>
          <compression xmlns=''>
              <method>zlib</method>
          </compression>
          <auth xmlns=''/>
          <register xmlns=''/>
      </body>
      

      这些是 body 标签内的 stream:features 标签的内容。 body 标签的 type='terminate',所以它告诉客户端关闭连接,Strophe 就是这么做的。此外,所有命名空间都丢失了。

      Openfire 应该发送的内容是这样的:

      <body xmlns='http://jabber.org/protocol/httpbind' xmlns:xmpp='urn:xmpp:xbosh' xmlns:stream='http://etherx.jabber.org/streams' sid='0630f9b79631f5ecb66d26313d34ce227262cf5d' wait='60' requests='2' inactivity='30' maxpause='120' polling='2' ver='1.8' from='localhost' secure='false' authid='2869001480' xmpp:version='1.0'>
          <stream:features xmlns:stream='http://etherx.jabber.org/streams'>
              <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
                  <mechanism>DIGEST-MD5</mechanism>
                  <mechanism>PLAIN</mechanism>
                  <mechanism>SCRAM-SHA-1</mechanism>
              </mechanisms>
              <compression xmlns=''>
                  <method>zlib</method>
              </compression>
              <register xmlns='http://jabber.org/features/iq-register'/>
          </stream:features>
      </body>
      

      (流:body 标签内的特征)。

      tl;dr StropheJS 关闭连接是预期的行为,您的 Openfire 版本的 BOSH 插件可能已损坏。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多