PacketCollector pollResult problem

I’m writing a XMPP web client using smack and ajax. Everything seems to work, except when I try to implement pollResult.

Within the jsp client, I am calling an Ajax getHTTP request that calls the following method. I am expecting the method to return a String of my latest result. Is this an operative approach? And if not, how should I implement the PacketCollector?

public String getMessages(XMPPConnection connection)


String message = null;

PacketTypeFilter filter = new PacketTypeFilter(Message.class);

PacketCollector collector = connection.createPacketCollector(filter);

Packet packet = collector.pollResult();

if (packet instanceof Message) {

Message msg = (Message) packet;


message = msg.getBody();


return message;


Still working on this. Does the PacketCollector also need a listener? It looks like you can create a PacketCollector object from both Chat and Connection. It would be really helpful if someone could post a code snippet for someone using pollResult, as using a listener does not seem to be feasible for a web client.

Whats wrong with your JSP? Does not poll messages you expect? maybe you are filtering the wrong type of messages. That was my case at the begining… Try this “permisive” filter.

PacketFilter filter = new PacketFilter() {

public boolean accept(Packet packet) {

return true;



This filter will let pass everything. Then you could learn what packet you are interested in.

And yes, using listeners is feasible for web clients using AJAX + longpoll or streaming.