WebSocket
class¶
Importing the WebSocket
from esmerald
is as simple as:
from esmerald import WebSocket
esmerald.WebSocket
¶
WebSocket(scope, receive, send)
Bases: WebsocketMixin
PARAMETER | DESCRIPTION |
---|---|
scope |
TYPE:
|
receive |
TYPE:
|
send |
TYPE:
|
Source code in lilya/websockets.py
19 20 21 22 23 24 25 26 |
|
set_session
¶
set_session(value)
Sets the value of a request session by passing a dictionary.
PARAMETER | DESCRIPTION |
---|---|
value |
TYPE:
|
Source code in lilya/_internal/_connection.py
175 176 177 178 179 |
|
clear_session
¶
clear_session()
Clears the scope session.
Source code in lilya/_internal/_connection.py
181 182 183 184 185 |
|
is_secure
¶
is_secure()
Check if the connection is secure (HTTPS).
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the connection is secure (HTTPS), False otherwise.
TYPE:
|
Source code in lilya/_internal/_connection.py
187 188 189 190 191 192 193 194 |
|
path_for
¶
path_for(name, /, **path_params)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
**path_params |
TYPE:
|
Source code in lilya/_internal/_connection.py
196 197 198 199 |
|
raise_for_disconnect
¶
raise_for_disconnect(message)
PARAMETER | DESCRIPTION |
---|---|
message |
TYPE:
|
Source code in lilya/websockets.py
28 29 30 |
|
raise_for_connection_state
async
¶
raise_for_connection_state()
Source code in lilya/websockets.py
32 33 34 |
|
receive
async
¶
receive()
Receive ASGI websocket messages, ensuring valid state transitions.
Source code in lilya/websockets.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
send
async
¶
send(message)
Send ASGI websocket messages, ensuring valid state transitions.
PARAMETER | DESCRIPTION |
---|---|
message |
TYPE:
|
Source code in lilya/websockets.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
accept
async
¶
accept(subprotocol=None, headers=None)
PARAMETER | DESCRIPTION |
---|---|
subprotocol |
TYPE:
|
headers |
TYPE:
|
Source code in lilya/websockets.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
receive_text
async
¶
receive_text()
Source code in lilya/websockets.py
125 126 127 128 129 130 |
|
receive_bytes
async
¶
receive_bytes()
Source code in lilya/websockets.py
132 133 134 135 136 137 |
|
receive_json
async
¶
receive_json(mode='text')
PARAMETER | DESCRIPTION |
---|---|
mode |
TYPE:
|
Source code in lilya/websockets.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
iter_text
async
¶
iter_text()
Source code in lilya/websockets.py
154 155 156 157 158 159 |
|
iter_bytes
async
¶
iter_bytes()
Source code in lilya/websockets.py
161 162 163 164 165 166 |
|
iter_json
async
¶
iter_json()
Source code in lilya/websockets.py
168 169 170 171 172 173 |
|
send_text
async
¶
send_text(data)
PARAMETER | DESCRIPTION |
---|---|
data |
TYPE:
|
Source code in lilya/websockets.py
175 176 |
|
send_bytes
async
¶
send_bytes(data)
PARAMETER | DESCRIPTION |
---|---|
data |
TYPE:
|
Source code in lilya/websockets.py
178 179 |
|
send_json
async
¶
send_json(data, mode='text')
PARAMETER | DESCRIPTION |
---|---|
data |
TYPE:
|
mode |
TYPE:
|
Source code in lilya/websockets.py
181 182 183 184 185 186 187 188 189 190 191 |
|
close
async
¶
close(code=1000, reason=None)
PARAMETER | DESCRIPTION |
---|---|
code |
TYPE:
|
reason |
TYPE:
|
Source code in lilya/websockets.py
193 194 |
|
esmerald.WebSocketDisconnect
¶
WebSocketDisconnect(code=1000, reason=None)
Bases: WebSocketDisconnect
Esmerald WebSocketDisconnect
PARAMETER | DESCRIPTION |
---|---|
code |
TYPE:
|
reason |
TYPE:
|
Source code in esmerald/websockets.py
15 16 |
|