Client Disconnect when power shutdown

Hai, i am new to Openfire Server and smack Library, i want to display presence in my application, i almost done XMPPConnection, disconnect when logout successfully., but my question is how to disconnect client when the abnormal condition occurs as such power shutdown or network failure ?.

I set in openfire system properties as xmpp.client.idle to 30000 (30 seconds), Please help me how to i handle that abnormal conditions, i am sending packet to the server for every 20 secs by setting as

XMPPConnection conn = (XMPPConnection)request.getSession().getAttribute(“xmppconn”);

Presence presence = new Presence(Presence.Type.available);


I think it’s not a good way to handle,

Please help me it’s thankfull for u all.

smack already sends KeepAlive packets, you don’t need to do it manually.

The server side timeout is the only thing you can use for abnormal termination. There is no way of knowing if the client is idle because it’s doing nothing, or someone pulled the cord.

If you don’t want to wait for the timeout to kick the login, set the resource policy on Openfire to kick the previous on repeat logins.

Thanks for your reply, Could you please explain about keepalive packets send from client to the server? I am always seeing the

Session Created,Session Last Active as same always in admin console, i didn’t do any packet exchange by doing any chats, as u told abnormal conditions should be handled only by session timeout and not other means of sending any packets for every 10 sec, to say the client is alive, how gmail handled this issues, when browser close and abnormal conditions occurs, it suddenly reflects in other side , how will be handled ? Please explain , if you have any code, please send me, I am in great struggle to handle, Please help me.


I don’t know how gmail does it, maybe they have a very short KeepAlive time and timeouts.

Have a look at org.jivesoftware.smack.SmackConfiguration where you can control the intervals or even turn it off. Also, KeepAlive is a “heartbeat” and not stanzas, therefore it doesn’t show up in the debugger.

Yes, Thanks, i also tried as you said and i set the setKeepAliveInterval(20000) from smackconfigration api, so that client will send keep alive requests to the server for 20 seconds, because as i said before i set xmpp.client.idle as 30000 (30 seconds), but it does not response for the abnormal coditions as power shutdown, it is always shows as online in server for this reason only i send a packet for every 20 seconds to the server, to know that client is alive to server, i don’t know this is right, please give me any solution to solve this issues.

Thanks a lot in advance.

can any one explain please where to set up Keep alive interval and timeouts for to disconnect the client from abnormal conditions.