...
.. warning::
**Version 3.0 introduces a backwards-incompatible change in the**
:meth:`~protocol.WebSocketCommonProtocol.recv` **API.**
**If you're upgrading from 2.x or earlier, please read this carefully.**
:meth:`~protocol.WebSocketCommonProtocol.recv` used to return ``None``
when the connection was closed. This required checking the return value of
every call::
message = await websocket.recv()
if message is None:
return
Now it raises a :exc:`~exceptions.ConnectionClosed` exception instead.
This is more Pythonic. The previous code can be simplified to::
message = await websocket.recv()
When implementing a server, which is the more popular use case, there's no
strong reason to handle such exceptions. Let them bubble up, terminate the
handler coroutine, and the server will simply ignore them.
In order to avoid stranding projects built upon an earlier version, the
previous behavior can be restored by passing ``legacy_recv=True`` to
:func:`~server.serve`, :func:`~client.connect`,
:class:`~server.WebSocketServerProtocol`, or
:class:`~client.WebSocketClientProtocol`. ``legacy_recv`` isn't documented
in their signatures but isn't scheduled for deprecation either.
Also:
* :func:`~client.connect` can be used as an asynchronous context manager on
Python ≥ 3.5.1.
* Updated documentation with ``await`` and ``async`` syntax from Python 3.5.
* :meth:`~protocol.WebSocketCommonProtocol.ping` and
:meth:`~protocol.WebSocketCommonProtocol.pong` support data passed as
:class:`str` in addition to :class:`bytes`.
* Worked around an asyncio bug affecting connection termination under load.
* Made ``state_name`` atttribute on protocols a public API.
* Improved documentation.