Fixed bug in handling of closed sockets when sending messages.