How to detect network failures

I’‘m using Smack to write to and read from a MUC. How can I detect network failures? If I unplug my network cable, it seems that a SocketException occurs during PacketReader.parsePackets, but this is outside any of my code, so I don’'t know how or where to catch that exception. Checking XMPPConnection.isConnected() or MultiUserChat.isJoined() shows no failure until after the SocketException. Any suggestions on how to quickly detect network failures so I can gracefully attempt a reconnection? Thanks.

Just implenent the ConnectionListener interface and put your disconnect handling code in connectionClosedOnError().

Look at the javadoc for XMPPConnection.

HTHs,

Karan

hey i’'ve followed the advice and implemented the ConnectionListener class then added it to my XMPPConnection within my applet.

What do you guys do with the Exception that is passed into the method connectionClosedOnError?

I want to send a msg back to my applet.

any help appreciated.

It seems that on Mac OS X, neither connectionClosed() nor connectionClosedOnError(Exception) are called in this circumstance (network cable unplugged, for instance). Has anybody else had this problem?

Correction: it takes something like 15-20 minutes for the listener to be notified of that connectionClosedOnError() on Mac. If I check the state of XMPConnection during this interval (after network cable unplugged, before notification received), it believes that it is Authenticated and Connected.