powered by Jive Software

How to recieve all packets

Hi i am making a bot application which has to recieve packets/ im messages fro any user

how can enable that which filter to use …how can revieve messages from any user ?

Implement the PacketListener interface, and add the implementing class as a packet listener to your XMPPConnection. Any packet sent to the JID of your bot will be sent there. You can check if( packet instanceof Message ) if you just want messages.

example:

XMPPConnection con = new XMPPConnection(“jabber.org”);

// login stuff here

con.addPacketListener(new PacketListener()

{

public void packetReceived(Packet packet)

if(packet instanceof Message)

{

// handle message

}

}

} );

/code

Hi I am using smack 2 api …addPacketListener takes 2 parameter 2nd being PacketFilter .So code snippet does not seem to work … As per smack java docs(there is no overidden method)

addPacketListener(PacketListener, PacketFilter) - Method in class org.jivesoftware.smack.XMPPConnection

Registers a packet listener with this connection.

So what kind packet filter I should add it accepts all packets ?

Since he is creating a bot, isn’'t it more natural to use a PacketCollector[/i] so that he can just block until he gets a packet? Or should one use a packet listener and do the blocking some other way?