Added logic for errors on sockets