powered by Jive Software

Urgent, How to receive the jabber server message?

Anyone can tell me how to receive the jabber server message?

My Code:

public class SimpleMessageListener extends Thread implements PacketListener {

public static void main(String[] args) throws Exception

{

XMPPConnection con = new XMPPConnection(“jabber.sztelecom.com”, 5222);

con.login(“wsdxj”, “000000”);

PacketFilter filter = new PacketTypeFilter(Message.class);

SimpleMessageListener listener = new SimpleMessageListener();

listener.start();

con.addPacketListener(listener, filter);

}

public void processPacket(Packet packet) //but this method never execute, why?

{

Message message = (Message)packet;

System.out.println("From: " + packet.getFrom());

System.out.println("Body: " + message.getBody());

System.out.println("----


");

}

public void run()

{

while (true)

{

try

{

Thread.sleep(1000);

}

catch (Exception e)

{ }

}

}

}

Thanks a lot.

Resolve it!

After Login, do it to notify the jabber server:

connection.sendPacket(new Presence(Presence.Type.AVAILABLE));[/b]

Then the listener will receive the message.

Get it!

connection.sendPacket(new Presence(Presence.Type.AVAILABLE));[/b]