noio_ws API

Connection object

class Connection(role, opcode_non_control_mod=None, opcode_control_mod=None)

The connection object which acts as a middle man between your application logic and your network io.

Parameters:
  • role (str) – Either 'CLIENT' or 'SERVER' used to set the Connection ‘s role.
  • opcode_non_control_mod (dict) – For example {3: 'latin-1'}. This adds extensibility for non-control frames. Valid ints are 3-7.
  • opcode_control_mod (dict) – For example {11: 'compare'}. This adds extensibility for control frames. Vaid ints are 11-15.
send(self, frame)

Prepares Frame objects, returning bytes ready to be sent over the network.

Parameters:frame (Frame) – Given a Frame object, returns a bytes object representing a websocket frame suitable to be sent over a network.
Returns:None
recv(self, bytechunk)

Takes raw bytes fresh from the informationsuperhighway and processes them.

Parameters:bytechunk (bytes) – Takes bytes and processes them with the internal receiver class, building a Message object.
Returns:None
next_event(self)

Checks to see if there is an event ready internally, handing it back to the caller.

Returns:Message object or Information.NEED_DATA

Frame object

class Frame(self, data, type, fin=True, status_code=None, rsv_1=None, rsv_2=None, rsv_3=None)

The object used to represent websocket frames for sending.

Parameters:
  • data (str/bytes) – A bytes or string object to be sent as the frame’s payload.
  • type (str) – The name of the opcode for the frame. For example 'text'.
  • fin (bool) – Indicates if the frame is the last the series.
  • status_code (int) – The int representing the status close for close frames.
  • rsv_1 (int) – Passing 1 turns on the frame’s first reserved bit.
  • rsv_2 (int) – Passing 1 turns on the frame’s second reserved bit.
  • rsv_3 (int) – Passing 1 turns on the frame’s third reserved bit.

Message object

class Message(self, message, type, reserved)

The object used to represent a received websocket frame. Returned to the caller of Connection.next_event() when there is an event ready.

.message

The frame’s payload data.

.type

The string representation of the opcode. For example 'text', 'continue', 'close'.

.reserved

A list in the format [Int, Int, Int] where a 1 or 0 represents a frame’s reserved bit has been turned on or left off. For example [1, 0, 0] indicates that the first reserved bit in a frame is on.

.time

A datetime object representing when the frame was received.