1
votes

I have my own configured OpenFire server. I have created two users user1 and user2 and I'm trying to send/receive messages between these users across the 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.

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("[email protected]", 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="[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>

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>[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>

Can somebody help me and say why my client doesn't prints incomimming messages on console, and why user2 doesn't receive messages; Logs doesn't contain any errors.

2
Addition: client is successfully connected to server, user1 is shown online in Miranda clientVitaly

2 Answers

0
votes

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. 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

0
votes

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. 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

[email protected]

and receiving a message from

[email protected]/Miranda

These are 2 different users. 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.

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.