简体   繁体   English

无法通过Smack API使用Openfire服务器发送/接收邮件

[英]Can't send/resecive messages with openfire server across Smack API

I have my own configured OpenFire server. 我有自己配置的OpenFire服务器。 I have created two users user1 and user2 and I'm trying to send/receive messages between these users across the Smack API. 我已经创建了两个用户user1user2并且试图通过Smack API在这些用户之间发送/接收消息。

I switched on debug mode in Smack API and can see that my dummy application sends and receives messages, but MessageListener doesn't work, it never invokes processMessage(Chat chat, Message message) method, also I can't see messages in the Miranda IM client of the user2. 我在Smack API中打开了调试模式,可以看到我的虚拟应用程序发送和接收消息,但是MessageListener不起作用,它从不调用processMessage(Chat chat, Message message)方法,在Miranda中也看不到消息用户的IM客户端2。

Code: 码:

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("user2@ejab.net.ru", new MessageListener() {
        public void processMessage(Chat chat, Message message) {
            System.out.println("Received message: " + message);
        }
    });
}

Here is my debug logs: 这是我的调试日志:

Sent log 发送日志

<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="user1@ejab.net.ru" from="user2@ejab.net/Smack" type="chat"><body>Hello world</body><thread>T0T5u0</thread></message>
<iq id="mir_148" to="user1@ejab.net/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>

Received log 收到日志

<?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>user2@ejab.net/Smack</jid></bind></iq>
<iq type="result" id="4KApN-1" to="user2@ejab.net/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="user2@ejab.net/Smack"><query xmlns="jabber:iq:roster"><item jid="user1@ejab.net" name="user1" subscription="both"/></query></iq>
<presence from="user1@ejab.net/Miranda" to="user2@ejab.net/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="user2@ejab.net/Smack" id="mir_147" from="user1@ejab.net/Miranda"><query xmlns="jabber:iq:version"/></iq>
<iq type="get" to="user2@ejab.net/Smack" id="mir_148" from="user1@ejab.net/Miranda"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
<message type="chat" to="user2@ejab.net/Smack" id="mir_151" from="user1@ejab.net/Miranda"><body>TEST</body></message>

Can somebody help me and say why my client doesn't prints incomimming messages on console, and why user2 doesn't receive messages; 有人可以帮我说一下为什么我的客户不在控制台上打印未发送的消息,以及为什么user2没有收到消息吗? Logs doesn't contain any errors. 日志不包含任何错误。

Both users actually need to open a chat to each other before receiving messages. 两个用户实际上都需要在接收消息之前彼此打开聊天。 You should open a chat between user1 and user2, register a MessageListener that will listen for messages send by user2 (the one you created actually listens to messages send by user2 and your message log is saying that you send a message from user2 to user1), then do the same the other way around. 您应该打开user1和user2之间的聊天,注册一个MessageListener来侦听user2发送的消息(您创建的侦听器实际上侦听user2发送的消息,并且消息日志说您是从user2向user1发送消息),然后反过来做同样的事情。 Finally send a message and you'll be able to process it. 最后发送一条消息,您将能够对其进行处理。

Also, just a comment, please be more specific in your titles as the api works well with openfire 另外,请仅发表评论,因为api与openfire配合良好,请在标题中更具体

I am somewhat confused by what you have said, what is in your code and what you are showing in your debug log. 我对您所说的内容,代码中的内容以及调试日志中显示的内容感到困惑。

Your code (and your post) say that you are logging in as user1 from the Smack client, but your log shows that you are sending as user2 and receiving from user1. 您的代码(和您的帖子)说您从Smack客户端以user1身份登录,但您的日志显示您以user2身份发送并从user1接收。 I am assuming that is just a simple error in your reporting. 我假设这只是您报告中的一个简单错误。

The real problem appears to be that you are sending a message to 真正的问题似乎是您正在向

user1@ejab.net.ru

and receiving a message from 并从收到消息

user1@ejab.net/Miranda

These are 2 different users. 这是2个不同的用户。 You appear to be sending to a different user than you are recieving from. 您似乎要发送给与接收方不同的用户。 Thus the reason the Miranda client does not recieve the message is because the Smack client did not send it to the right JID, and of course is the same reason why you did not receive anything in your listener. 因此,Miranda客户端未接收到消息的原因是Smack客户端未将其发送到正确的JID,这当然与您在侦听器中未收到任何消息的原因相同。

On the flip side, to receive the incoming message, you can create a ChatManagerListener and then you will get your incoming chat from the Miranda client. 另一方面,要接收传入的消息,可以创建一个ChatManagerListener ,然后从Miranda客户端获取传入的聊天。

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

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