Fixed socket data-loss catch and possibility of socket not closing properly.