我有我自己配置的OpenFire服务器。我创建了两个用户user1
和user2
,我试图通过Smack API在这些用户之间发送/接收消息。不能通过Smack API与openfire服务器发送/重新发送消息
我的Smack API开启调试模式,可以看到我的虚拟应用程序发送和接收消息,但MessageListener
不起作用,它永远不会调用processMessage(Chat chat, Message message)
方法,也是我无法看到的米兰达IM客户端的消息user2。
代码:
public class Main {
public static void main(String[] args) throws XMPPException, InterruptedException {
sendJabberMessage();
while (true) {
Thread.sleep(50);
}
}
public static void sendJabberMessage() throws XMPPException {
XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config = new ConnectionConfiguration("ejab.net", 5222, "ejab.net");
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login("user1", "password");
Chat chat = connection.getChatManager().createChat("[email protected]", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println("Received message: " + message);
}
});
}
这里是我的调试日志:
发送日志
<stream:stream to="ejab.net" 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="ejab.net" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">b3BlcmF0b3IyQGVqYWIubmV0AG9wZXJhdG9yMkBlamFiLm5ldAA4ZGRYUGdQYTU0MlQ=</auth>
<stream:stream to="ejab.net" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="4KApN-0" type="set"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>Smack</resource></bind></iq>
<iq id="4KApN-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="ejab.net" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="4KApN-2" type="get"><query xmlns="jabber:iq:roster"></query></iq>
<presence id="4KApN-3"></presence>
<message id="4KApN-4" to="[email protected]" from="[email protected]/Smack" type="chat"><body>Hello world</body><thread>T0T5u0</thread></message>
<iq id="mir_148" to="[email protected]/Miranda" type="result"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="client" name="Smack" type="pc"/><feature var="http://jabber.org/protocol/xhtml-im"/><feature var="http://jabber.org/protocol/muc"/><feature var="http://jabber.org/protocol/commands"/></query></iq>
接受的日志
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ejab.net" id="4942adbf" xml:lang="en" version="1.0"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>JIVE-SHAREDSECRET</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms></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="ejab.net" id="4942adbf" xml:lang="en" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>JIVE-SHAREDSECRET</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-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>
<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="ejab.net" id="4942adbf" 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="4KApN-0" to="ejab.net/4942adbf"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[email protected]/Smack</jid></bind></iq>
<iq type="result" id="4KApN-1" to="[email protected]/Smack"><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="ejab.net" id="4942adbf" 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="4KApN-2" to="[email protected]/Smack"><query xmlns="jabber:iq:roster"><item jid="[email protected]" name="user1" subscription="both"/></query></iq>
<presence from="[email protected]/Miranda" to="[email protected]/Smack"><priority>0</priority><c xmlns="http://jabber.org/protocol/caps" node="http://miranda-im.org/caps" ver="0.9.28.0" ext="pmuc-v1 mood activity mir_notes"/><x xmlns="vcard-temp:x:update"><photo/></x><status>Yep, I'm here.</status></presence>
<iq type="get" to="[email protected]/Smack" id="mir_147" from="[email protected]/Miranda"><query xmlns="jabber:iq:version"/></iq>
<iq type="get" to="[email protected]/Smack" id="mir_148" from="[email protected]/Miranda"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
<message type="chat" to="[email protected]/Smack" id="mir_151" from="[email protected]/Miranda"><body>TEST</body></message>
有人可以帮助我,说为什么我的客户不打印在控制台上消减消息,以及为什么user2不接收消息;日志不包含任何错误。
此外:客户端已成功连接到服务器,user1显示在Miranda客户端在线显示 – Vitaly
[得到同样的问题,但解决此问题后,在第一次尝试收到我的消息](http://stackoverflow.com/questions/28023749 /发送和接收的消息贯通XMPP协议上机器人/ 28040155#28040155) – learner