powered by Jive Software

Customize the messages

Hi everyone, I want to use the StanzaCollector and StanzaListener to process the packets.
I also want to catch the message that the debugger catches when setting the setDebuggerEnabled is true.
I use the Smack version is 4.2.3
Here is my code:

import java.io.IOException;

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

public class SmackClient {
    public static void main(String []args) throws InterruptedException {
        // Create a connection and login to the example.org XMPP service.
        XMPPTCPConnectionConfiguration config;
        try {
            config = XMPPTCPConnectionConfiguration.builder()
                    .setUsernameAndPassword("admin", "password")

            AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
            StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class));

            StanzaCollector myCollector = conn2.createStanzaCollector(filter);
            StanzaListener myListener = new StanzaListener() {
                public void processStanza(Stanza stanza) {
                    // Do something with the incoming stanza here._
                    try {
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
            conn2.addSyncStanzaListener(myListener, filter);
        } catch (XMPPException e) {
            // TODO Auto-generated catch block
        } catch (SmackException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block

Unfortunately, my code is not worked well and I cannot receive any debugged messages.
What’s wrong with this code?


You block indefinitely in a sync stanza listener.