powered by Jive Software

Trying to implement chat in servlet context

Every now and then the MultiUserChat works in an AJAX/Java Servlet enviroment… I use pollMessage() and it will work like a charm the first time. Then after a while it stops working and doesn’‘t work for a couple days. I read an archived post about pollMessage not working because of something related to the threadId, but this is 2006 and that was from 2004. Here is some very simple code from that threadId that doesn’'t work in for me either:

<%

if (session.getAttribute(“chatObject”) == null) {

XMPPConnection conn = new XMPPConnection(“localhost”);

conn.loginAnonymously();

MultiUserChat newChat = new MultiUserChat(conn, “test@chat.localhost”);

newChat.sendMessage(“Howdy!”);

session.setAttribute(“chatObject”, newChat);

session.setAttribute(“connObject”, conn);

} else {

XMPPConnection conn = (XMPPConnection)session.getAttribute(“connObject”);

MultiUserChat newChat = (MultiUserChat)session.getAttribute(“chatObject”);

Message message = newChat.pollMessage();

String mbody ="";

if (message != null) {

mbody = message.getBody();

out.println(mbody);

} else {

if (message == null) {

out.println(“null”);

}

}

}

%>

I believe the thread suggested using a messageListener but I don’‘t see how that will work in a serlvet context. Why doesn’‘t this very simple and intuitive examples doens’'t work and/or how can I make it work? Please help!