A single WebSocket message. Note that you’ll be seeing the subclasses of this instead; see below.
Should never appear if you’re using a Reader (it handles pings automatically.)
Whether this message is a response to a previously sent ping.
Whether this message is some binary data.
Whether this message is text (in UTF-8, I think?)
Whether this message is the last one sent over this channel. The connection has already been closed.
A message with type other than “text”. Is a subclass of bytes
; contains the data.
A message with type “text”. Is a subclass of str
; contains the data, too.
A special coroutine-like object that waits for the next message and returns it
when used with yield from
. Raises asyncio.CancelledError
if the connection
gets closed; the first argument of the exception, if it exists, is
a Message received before closing the connection (it will have is_close
set to True
.) Other than that, it can send data, too:
Send a ping. This method is a coroutine which waits until all data is sent.
(Note that waiting on it is not necessary to send data; feel free to forget the
yield from
.)
Respond to a ping. Done automatically. Also a coroutine.
Send some text. A coroutine.
Send some binary data. A coroutine.
Send a close
message. No other messages can be sent after that.
This method also cancels the task that calls it, just to drive that point home.
A coroutine.
Connect multiple WebSocket streams into a
read-only one that emits data from all of these streams. Instead of just message
, it
returns (stream, message)
pairs when yielded from. The first websocket to disconnect
cancels the task.
Create a request handler that establishes a WebSocket connection and calls into the handler, which should accept all the same arguments as a normal request handler would with the addition of one more positional argument, which is a WebSocket object.
Same as endpoint, only instead of a single connection the handler should
accept a set of n
connections. The clients may have to wait until there are
enough connections to call the handler.
Create a client-side half of the WebSocket stream given a standard asyncio StreamReader
and StreamWriter
. Note that this is a server-side framework, so client-side functionality
is not really outstanding; for example, this function only supports HTTP/1.1 and only
sends the minimal headers (which are hardcoded). Returns a WebSocket
object.
io = yield from $ asyncio.open_connection 'websocket.host' 80
ws = yield from $ websocket.client '/websocket_node/' *: io
ws.text 'ok'