繁体   English   中英

openfire smack发送数据包404错误是什么意思?

[英]openfire smack sending packet 404 error means?

使用Smack将数据包发送到openfire时,出现错误remote-server-not-found(404)。 谁能解释这个错误是什么意思? 这意味着无法连接到服务器或数据包有问题?

        PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
        PacketCollector response = connection.createPacketCollector(responseFilter);

        connection.sendPacket(packet);



        // Wait up to a certain number of seconds for a reply.
        Packet result = response.nextResult(timeout);



        // Stop queuing results
        response.cancel();



        if (result == null) {
            throw new XMPPException("No response from server.");
        }
        else if (result.getError() != null) {  

            System.out.println("error:"+result.getError());   //i get error here.... 404
            throw new XMPPException(result.getError());
        }

// ---以下是我如何连接到openfire的方法。

        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222);
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(true);



        XMPPConnection connection = new XMPPConnection(config);
        // Connect to the server
        connection.connect();
        // Log into the server
        connection.login("test", "test","testresource");

我附加了从日志中收到的xmpp xml

发送中...

<stream:stream to="localhost" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></auth>
<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">Y2hhcnNldD11dGYtOCx1c2VybmFtZT0idGVzdCIscmVhbG09InpoYW5nIixub25jZT0ieHZacDFOdHlkcld6MVBzOFA0UGlnbWgrbHRieWtyclNYU0NLWVJaRyIsbmM9MDAwMDAwMDEsY25vbmNlPSIxdThheGtJSWgrSzhBLzFBSDRtTHJ5OUxDTE1OSFpBa0xvdlVGcVFGIixkaWdlc3QtdXJpPSJ4bXBwL3poYW5nIixtYXhidWY9NjU1MzYscmVzcG9uc2U9MGE3YzEzOWRkODliZjk5NDcxN2ZiNjQzY2E5NWM3ZDUscW9wPWF1dGgsYXV0aHppZD0idGVzdCI=</response>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="CHWuJ-0" type="set"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>god</resource></bind></iq>
<iq id="CHWuJ-1" type="set"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
<compress xmlns='http://jabber.org/protocol/compress'>
<method>zlib</method></compress>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="CHWuJ-2" type="get"><query xmlns="jabber:iq:roster"></query></iq>
<presence id="CHWuJ-3"></presence>
<iq id="CHWuJ-4" to="pubsub.my.openfire.server" type="set"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node='TestNode2323'/><configure><x xmlns="jabber:x:data" type="submit"><field var="pubsub#persist_items" type="boolean"><value>0</value></field><field var="pubsub#deliver_payloads" type="boolean"><value>1</value></field><field var="pubsub#access_model" type="list-single"><value>open</value></field></x></configure></pubsub></iq>

接收....

<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls>
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>
zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features><proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression>
<auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
<challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
cmVhbG09InpoYW5nIixub25jZT0ieHZacDFOdHlkcld6MVBzOFA0UGlnbWgrbHRieWtyclNYU0NLWVJaRyIscW9wPSJhdXRoIixjaGFyc2V0PSJ1dGYtOCIsYWxnb3JpdGhtPSJtZDUtc2VzcyI=</challenge>
<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
cnNwYXV0aD1jOWIyOWIxYTMwN2Q5ZjdkYmZiOGM4MDBkMTU4OWFmZQ==</success>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
<iq type="result" id="CHWuJ-0" to="xuser/d0689fdf"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>test@xuser/god</jid></bind></iq>
<iq type="result" id="CHWuJ-1" to="test@xuser/god"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
<compressed xmlns='http://jabber.org/protocol/compress'/>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
<iq type="result" id="CHWuJ-2" to="test@xuser/god"><query xmlns="jabber:iq:roster"><item jid="test" name="test" subscription="none"/></query></iq>
<iq type="error" id="CHWuJ-4" to="test@xuser/god" from="pubsub.my.openfire.server"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node="TestNode2323"/><configure><x xmlns="jabber:x:data" type="submit"><field var="pubsub#persist_items" type="boolean"><value>0</value></field><field var="pubsub#deliver_payloads" type="boolean"><value>1</value></field><field var="pubsub#access_model" type="list-single"><value>open</value></field></x></configure></pubsub><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

解释..

<iq id="CHWuJ-0" to="xuser/d0689fdf" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>test@xuser/god</jid></bind></iq>
<iq id="CHWuJ-1" to="test@xuser/god" type="result"></iq>
<iq id="CHWuJ-2" to="test@xuser/god" type="result"><query xmlns="jabber:iq:roster"><item jid="test" name="test" subscription="none"></item></query></iq>
<iq id="CHWuJ-4" to="test@xuser/god" from="pubsub.my.openfire.server" type="error"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node='TestNode2323'/><configure xmlns="http://jabber.org/protocol/pubsub"><value>0</value></configure></pubsub><error code="404" type="CANCEL"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

我遇到了刚解决的类似问题。

我有一个运行在本地计算机上的Openfire服务器,并且正在使用Smack API与服务器进行通信。 在Openfire中,我定义了两个用户:发送者和接收者。 我没有使用电子邮件地址作为用户名。

在我的代码中,我在一个线程上有一个“发送方”连接,在另一个线程上有一个“接收方”的连接。 最初,在发送消息时,我从Openfire服务器收到remote-server-not-found(404)错误响应。 我发现,在由发送方创建聊天请求时,我需要将参与者设置为receiver@[Openfire domain]

因此,如果您的Openfire域是foo ,则将是receiver@foo 显然,这不是“接收者”用户的电子邮件地址。 通常,域实际上只是运行Openfire服务器的计算机的名称。

该错误由服务器生成(请参阅XMPPError )。 我尝试获取完全相同的错误代码,但失败了。 但是,我感觉这是服务器的配置错误。 您是否尝试过与其他客户端连接,例如使用您喜欢的Jabber客户端?

您也可以尝试启用Smacks XMPP调试功能并发布导致错误的消息:

static {
    XMPPConnection.DEBUG_ENABLED = true;
}

(您可能还想添加smackx-debug.jar以获得更多调试功能)

请检查数据包是否发送给正确的用户!

您应该为iq数据包的“ to”属性设置有效的JID,以便服务器可以将数据包发送到接收方。 我之前收到此错误是因为我为数据包设置了错误的JID。

顺便说一句,您可以在代码中添加XMPPConnection.DEBUG_ENABLED = true来查看发送的内容或在openfire Web控制台中查看错误日志,并且可能会发现类似以下错误:尝试连接到远程服务器时出错:theWrongHost(DNS查找: theWrongHost:5269)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM