1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
WebSocket Echo Server and Client
================================
This example shows how to set and get custom HTTP headers for using during the initial WebSocket opening handshake.
Running
-------
Run the server by doing
python server.py debug
Run the client by doing
python client.py ws://127.0.0.1:9000 debug
The client will send a custom HTTP header `MyCustomClientHeader` during the initial WebSocket opening handshake:
User-Agent: AutobahnPython/0.6.0
Host: 127.0.0.1:9000
Upgrade: WebSocket
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
MyCustomClientHeader: Bazbar
Sec-WebSocket-Key: tI9KmKOGOAGTxgWfVn13zg==
Sec-WebSocket-Version: 13
The server will respond with custom HTTP headers
HTTP/1.1 101 Switching Protocols
Server: AutobahnPython/0.6.0
Upgrade: WebSocket
Connection: Upgrade
MyCustomServerHeader: Foobar
MyCustomDynamicServerHeader1: Hello
MyCustomDynamicServerHeader2: Bazbar
Sec-WebSocket-Accept: pQklbTbzxoUDuSDHpiYJThfd4vo=
where `MyCustomServerHeader` is a custom header sent to any connecting client (defined on the `WebSocketServerFactory`) and `MyCustomDynamicServerHeader1` and `MyCustomDynamicServerHeader2` are custom headers which values can be specific to the connecting client (and set within `onConnect`).
|