Added exception handling if server closes connection.