powered by Jive Software

Receiving messages


I’‘m new with Smack and my engish is not so good, I’'m sorry.

I have a problem with receiving messages from server. This is my code:

try {
            connection = new XMPPConnection(server, 5222);
            connection.login(user, password, resource);             PacketListener messageListener = new PacketListener() {
                public void processPacket(Packet packet) {
                    Message message = (Message) packet;
                    String from = message.getFrom();
                    String body = message.getBody();
            };             connection.addPacketListener(messageListener, new PacketTypeFilter(
        } catch (XMPPException ex) {

And when I send a message to JID, that I’'m logged on, nothing happend. What should I do?

Thanks in advance!

The code looks good to me. You can open a debugger to check if your client is receiving the XML packet.

An almost foolish question: is your test application still running when the other client sends the message? I mean, is your connection still open? From your code extract I cannot be sure of that.


– Gato

Yes, my application is running all time, I have send online presence and I can send messages to the others. Debugger isn’'t involved incoming packets.

Do I undestand it correct? The PacketListener (in my code object messageListener) receives all messages from the server, which were sent to my JID?

Have you been able to open the debugger? Have you seen in the debugger the xml of the Message you are looking for? If your debugger is not showing any message then your PacketListener won’‘t process the message you are expecting. We should then try to find out why the server is not sending to your client the message. What’‘s the JID of your client? And what’'s the TO attribute of the Message that other clients tried to send to your client?

Yes. Your PacketListener will listen for any Message that the server sent you. That’'s why I want to check with the debugger that your client is actually receiving those packets.


– Gato

I have sent messages to my application with Trillian. Now I oppened an another client (Pandion) and all works fine, I receive messages. It was possibly a problem with Trillian…

Thank You for your time!

P.S. I must say, that Smack is a great and very powerful tool!

Best Regards!

PacketListener is interface how can we instanciate

when i tryed this programm i am getting an error

plz give me suggesion