Smack provides a flexible framework for processing incoming packets using two
constructs:
*`org.jivesoftware.smack.PacketCollector` -- a class that lets you synchronously wait for new packets.
*`org.jivesoftware.smack.PacketListener` -- an interface for asynchronously notifying you of incoming packets. A packet listener is used for event style programming, while a packet collector has a result queue of packets that you can do polling and blocking operations on. So, a packet listener is useful when you want to take some action whenever a packet happens to come in, while a packet collector is useful when you want to wait for a specific packet to arrive. Packet collectors and listeners can be created using an `XMPPConnection` instance.
The `org.jivesoftware.smack.filter.PacketFilter` interface determines which
specific packets will be delivered to a `PacketCollector` or `PacketListener`.
Many pre-defined filters can be found in the `org.jivesoftware.smack.filter`
package.
The following code snippet demonstrates registering both a packet collector
and a packet listener:
```
// Create a packet filter to listen for new messages from a particular
// user. We use an AndFilter to combine two other filters._
PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class),