More robust connection handling with timeouts, expect and send pings.