Skip to content

Commit

Permalink
Clarify the rule for websocket handling
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed May 26, 2015
1 parent f3f7ba7 commit 4c8f54d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions docs/client_websockets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WebSockets Client

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

You have to use the :func:`aiohttp.ws_connect()` function for client
You have to use the :func:`ws_connect()` coroutine for client
websocket connection. It accepts a *url* as a first parameter and returns
:class:`ClientWebSocketResponse`, with that object you can communicate with
websocket server using response's methods:
Expand All @@ -36,10 +36,19 @@ websocket server using response's methods:
elif msg.tp == aiohttp.MsgType.error:
break
You can have the only websocket reader task (which can call ``yield
from ws.receive()``) and multiple writer tasks which can only send
data asynchronously (by ``yield from ws.send_str('data')`` for
example).
If you prefer to establish *websocket client connection* from
:class:`~aiohttp.client.ClientSession` object please use
:meth:`aiohttp.client.ClientSession.ws_connect` coroutine::

session = aiohttp.ClientSession()
ws = yield from session.ws_connect(
'http://webscoket-server.org/endpoint')


You **must** use the only websocket task for both reading (e.g ``yield
from ws.receive()``) and writing but may have multiple writer tasks
which can only send data asynchronously (by ``yield from
ws.send_str('data')`` for example).


ClientWebSocketResponse
Expand Down
7 changes: 4 additions & 3 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,10 @@ using response's methods:
return ws
You can have only one websocket reader task (which can call ``yield
from ws.receive()``) and multiple writer tasks which can only send
data asynchronously (by ``yield from ws.send_str('data')`` for example).
You **must** use the only websocket task for both reading (e.g ``yield
from ws.receive()``) and writing but may have multiple writer tasks
which can only send data asynchronously (by ``yield from
ws.send_str('data')`` for example).
.. _aiohttp-web-exceptions:
Expand Down

0 comments on commit 4c8f54d

Please sign in to comment.