Added handling of IOException when sending or receiving