How Do I Terminate A Chat Session

Hi, I’‘m creating a Chat session with another user by calling myConnection.createChat(“useraddress”). Once I’‘m done chatting with the user, I close my chat window and I want to terminate the Chat session without breaking my XMPPConnection. There doesn’‘t seem to be a way to do that, so the result is that the other user can keep typing messages into their window and my listener keeps getting them. I can remove the listener but the other user doesn’‘t know I’‘m not listening anymore. I’‘m sure there’'s a simple way to do this. Thanks!

Charlie

When you close the chat window:

Set the chat object to null.

Remove the MessageListner from the xmppconnection.

If the other user sends another message after this, it will be treated as a new incoming chat (assuming your program is listening for this).

There’'s no definite way for the other user to know that your user has closed the chat window. Normally people send a “bye” message before they finish chatting.

You could automatically send such a message when the chat window is closed, though you’'d want it configurable as to

a) whether it is done or not and

b) what “goodbye” message to send.

HTH, Pheet

Hey Guys,

I just wanted to add a little more of information about how Smack works. When you send the #createChat() to the XMPPConnection a Chat object is created. This object will add its own listeners on the connection so all you need to do for getting the Chat messages is send #pollMessage or #nextMessage to the Chat object.

When the Chat object is garbage collected the listeners that the Chat added to the connection will be automatically removed. So you don’'t have to take care of that part. So when the window is closed all you need to do is clean the reference to the Chat object as Pheet correctly suggested.

Regards,

– Gato