Hi all,
I'm using Smack 3.2 with ejabberd. The first client sends messages continuously to the second. For the second client, I attached a chat listener to discover the first created chat, assign a message listener, and then removing this chat listener. The problem is, after successfully receiving a number of messages the assigned message listener stops working while I can see messages still coming in Smack debugger. I found that if I dont remove the chat listener, client 2 message listener works all the time, because what happens is that client 1 keeps creating a new chat after sending a number of messages. Is this an expected behaviour? Please help.
Here is my code:
Sending:
Chat chat= conn1.getChatManager().createChat(jid2, null);
for(int i=0; i<100; i++){
chat.sendMessage(msg);
Thread.sleep(100);
}
Receiving:
conn2.getChatManager().addChatListener(new ChatManagerListener(){
publicvoid chatCreated(Chat chat, boolean createdLocally)
{
int t=0;
if(!createdLocally){
System.out.println("chat created by " + chat.getParticipant());
chat.addMessageListener(new MessageListener(){
publicvoid processMessage(Chat chat, Message msg){
System.out.println(msg.getBody());
}
});
t=1;
}
if(t==1)
conn.getChatManager().removeChatListener(this);
}
});