@@ -12,7 +12,7 @@ WebSockets Client
12
12
13
13
:mod: `aiohttp ` works with client websockets out-of-the-box.
14
14
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
16
16
websocket connection. It accepts a *url * as a first parameter and returns
17
17
:class: `ClientWebSocketResponse `, with that object you can communicate with
18
18
websocket server using response's methods:
@@ -36,10 +36,19 @@ websocket server using response's methods:
36
36
elif msg.tp == aiohttp.MsgType.error:
37
37
break
38
38
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).
43
52
44
53
45
54
ClientWebSocketResponse
0 commit comments