I finally got it working. First I used
connection.setExceptionListener() function and the exception listener will indicate the error. Then I used a timer to reconnect until new connection is built. But another problem accurs. Although the new connection replaces the old connection (also called close() for the old connection), it seems the old connection still reports "ping timeout" exception although the new connection is working fine. So I set the exception listener as null and closed the connection immediately after receiving the connection exception. The "ping timeout" is gone. But I'm not sure whether it is the correct way. Anybody has any idea about this?
I think that is the right solution as well. I have done the same thing in my Code. For more information on what I have written please refer to the following url, which is in the jboss.org as well.. I have tried to give a detailed description, Hope that can help you out.