added the logic to clean receive buffer when disconnected