Test connection and automatically reconnect