解决与openfire和波什的连接问题

时间:2014-06-24 19:05:28

标签: xmpp openfire strophe bosh

我使用了crossdomain中的示例连接到我的本地openfire xmpp服务。 只需更改BOSH网址即可容纳我当地的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进行测试并且有效)

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

您可以通过让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>

(stream:body标签内部的功能)。

tl; Dr StropheJS关闭连接是预期的行为,你的Openfire版本的BOSH插件可能已经坏了。

相关问题