return self.stream.write(frame)
def write_message(
- self, message: Union[str, bytes], binary: bool = False
+ self, message: Union[str, bytes, dict], binary: bool = False
) -> "Future[None]":
"""Sends the given message to the client of this Web Socket."""
if binary:
opcode = 0x2
else:
opcode = 0x1
+ if isinstance(message, dict):
+ message = tornado.escape.json_encode(message)
message = tornado.escape.utf8(message)
assert isinstance(message, bytes)
self._message_bytes_out += len(message)
future_set_result_unless_cancelled(self.connect_future, self)
def write_message(
- self, message: Union[str, bytes], binary: bool = False
+ self, message: Union[str, bytes, dict], binary: bool = False
) -> "Future[None]":
"""Sends a message to the WebSocket server.