'Close the websocket and connection, sending the specified code and
message.  The underlying socket object is _not_ closed, that is the
responsibility of the initiator.'

def close(self, code=1000, message=''):

    if self.closed:
        self.current_app.on_close(MSG_ALREADY_CLOSED)
    try:
        message = self._encode_bytes(message)
        self.send_frame(message, opcode=self.OPCODE_CLOSE)
    except WebSocketError:
        self.logger.debug('Failed    to    write    closing    frame    ->    closing    socket')
    finally:
        self.logger.debug('Closed    WebSocket')
        self.closed = True
        self.stream = None
        self.raw_write = None
        self.raw_read = None
        self.environ = None
