Fix send/receive errors - added socket closed checks