Skip to content

Commit 4c8f54d

Browse files
committed
Clarify the rule for websocket handling
1 parent f3f7ba7 commit 4c8f54d

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docs/client_websockets.rst

+14-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WebSockets Client
1212

1313
:mod:`aiohttp` works with client websockets out-of-the-box.
1414

15-
You have to use the :func:`aiohttp.ws_connect()` function for client
15+
You have to use the :func:`ws_connect()` coroutine for client
1616
websocket connection. It accepts a *url* as a first parameter and returns
1717
:class:`ClientWebSocketResponse`, with that object you can communicate with
1818
websocket server using response's methods:
@@ -36,10 +36,19 @@ websocket server using response's methods:
3636
elif msg.tp == aiohttp.MsgType.error:
3737
break
3838
39-
You can have the only websocket reader task (which can call ``yield
40-
from ws.receive()``) and multiple writer tasks which can only send
41-
data asynchronously (by ``yield from ws.send_str('data')`` for
42-
example).
39+
If you prefer to establish *websocket client connection* from
40+
:class:`~aiohttp.client.ClientSession` object please use
41+
:meth:`aiohttp.client.ClientSession.ws_connect` coroutine::
42+
43+
session = aiohttp.ClientSession()
44+
ws = yield from session.ws_connect(
45+
'http://webscoket-server.org/endpoint')
46+
47+
48+
You **must** use the only websocket task for both reading (e.g ``yield
49+
from ws.receive()``) and writing but may have multiple writer tasks
50+
which can only send data asynchronously (by ``yield from
51+
ws.send_str('data')`` for example).
4352

4453

4554
ClientWebSocketResponse

docs/web.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,10 @@ using response's methods:
416416
417417
return ws
418418
419-
You can have only one websocket reader task (which can call ``yield
420-
from ws.receive()``) and multiple writer tasks which can only send
421-
data asynchronously (by ``yield from ws.send_str('data')`` for example).
419+
You **must** use the only websocket task for both reading (e.g ``yield
420+
from ws.receive()``) and writing but may have multiple writer tasks
421+
which can only send data asynchronously (by ``yield from
422+
ws.send_str('data')`` for example).
422423
423424
424425
.. _aiohttp-web-exceptions:

0 commit comments

Comments
 (0)