'Sends the given message to the client of this Web Socket.
The message may be either a string or a dict (which will be
encoded as json).  If the ``binary`` argument is false, the
message will be sent as utf8; in binary mode any byte string
is allowed.
If the connection is already closed, raises `WebSocketClosedError`.
.. versionchanged:: 3.2
`WebSocketClosedError` was added (previously a closed connection
would raise an `AttributeError`)'

def write_message(self, message, binary=False):

    if (self.ws_connection is None):
        raise WebSocketClosedError()
    if isinstance(message, dict):
        message = tornado.escape.json_encode(message)
    self.ws_connection.write_message(message, binary=binary)
