powered by Jive Software

Updating a JSP with messages received in Smack

Hello all,

I am writing a JSP messenger client with the Smack API but I am stuck in displaying the received messages. More precisely, I have tried two methods of doing this:

  • registering a listener with the XMPP connection, addListener. The downside here is that I can't make changes to the JSP page inside the listener (only final variables are allowed inside an inner class).
  • defining a packet collector and polling for new results. I want to avoid polling too often so that's why I am waiting for a new message when there is one. Also, how would the JSP/Javascript look in this case? as one does not know the time interval to refresh the iframe where the messages are displayed.

In conclusion, I want to receive a message only whenever one is available (instead of constantly polling), but don’t have the experience in JSP/JavaScript to manipulate the results from Java. A sketch/directions would be very much valuable in making some progress. Thank you very much in advance!


here are links that work:

#addListener: http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/XMPPConnection.html#addPacketListener(org.jivesoftware.smack.PacketListene r,%20org.jivesoftware.smack.filter.PacketFilter)

#nextResult: http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/PacketCollector.html#nextResult()