gpt4 book ai didi

java - openfire smack发送包404错误是什么意思?

转载 作者:行者123 更新时间:2023-11-29 09:51:19 25 4
gpt4 key购买 nike

当使用 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 服务器的机器的名称。

关于java - openfire smack发送包404错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1558050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com