In the first case, <presence type='unavailable'/>
does not always actually disconnect you; in your server, it looks like it might be, but your client is auto-reconnecting. delete xmpp
is not actually causing your object to be cleaned up, it's just removing it from the local namespace.
In the second case send()
isn't writing your stanza to the underlying socket immediately. If you close the socket with end()
right afterwards, the socket is closed when the write actually happens.
If you add a short timeout after you call send()
, before calling end()
it will work. To make it good, you'll want your library developers to give you a callback when send()
has actually written to the socket.