Add debug message to check reconnection timeout.
Added keepalive command and fixed bug with connection timeout