Writer

You should not make an instance of the WebSocketWriter class yourself, rather you should only make use of it through websocket.client.Client.writer

>>> client.writer.send('Hello World!')
class websocket.stream.writer.WebSocketWriter(writer, loop)[source]
Variables:closed – True iff the server has sent a close frame to the client.
feed(buffer, op_code=None, chunksize=1024, drain_every=4096, force=False)[source]

Feed the contents of a Buffer to the client in chunksize fragments.

Parameters:
  • buffer (Buffer) – The buffer to read from
  • op_code (int) – The type of data to send, see DataType, if None try to read buffer.data_type as if buffer was a WebSocketReader
  • chunksize (int) – The size of each fragment
  • drain_every (int) – How often we forcefully drain the writer
  • force (bool) – If true send message even if the connection is closing e.g. we got valid message after having previously been sent a close frame from the client or after having received invalid frame(s)
fragment()[source]

Create a async context manager that can send fragmented messages.

Returns:FragmentContext
ping(payload=b'')[source]

Send a ping to the client.

Parameters:payload (bytes) – The payload to send with the ping.
pong(length, payload)[source]

Send a pong to the client.

Parameters:
  • payload (bytes) – The payload to send with the ping.
  • length (int) – The length of the payload.
send(data, force=False)[source]

Send some data to the client, the type of data is determined from the data parameter.

Parameters:
  • data – The data you wish to send, must be either str or bytes.
  • force (bool) – If true send message even if the connection is closing e.g. we got valid message after having previously been sent a close frame from the client or after having received invalid frame(s)
write_frame(header, data, length)[source]

Low level method to write a frame to the client, does not flush.

Parameters:
  • header – The frame header, containing the frame type and the fin bit
  • data – The data to include in the frame
  • length – The length of the data