Added code to try reconnect after send/recv loops detecting disconnection.