https://github.com/lucaspar/websockets-demo
Scenarios involving websocket connections.
https://github.com/lucaspar/websockets-demo
python-websocket websocket-demo websockets
Last synced: 8 months ago
JSON representation
Scenarios involving websocket connections.
- Host: GitHub
- URL: https://github.com/lucaspar/websockets-demo
- Owner: lucaspar
- Created: 2023-12-04T15:28:27.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T23:16:25.000Z (over 1 year ago)
- Last Synced: 2025-03-16T10:42:01.132Z (12 months ago)
- Topics: python-websocket, websocket-demo, websockets
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Websocket Demos
Install dependencies:
```bash
uv sync
```
## Increased Backpressure Demo
This demonstrates an increase in the backpressure of a websocket connection by sending messages faster than they can be processed.
Eventually the connection is closed with either one of these generic errors:
+ A `1006` [error code](https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1) on the server side (connection was closed abnormally) and the same on the client side.
+ A `1011` error code (internal error). The client fails immediately after the connection is closed.
## Observations
### Server state / lost messages
Even though the underlying TCP guarantees the delivery of the messages, that does not mean the client has a chance to process all messages received in this demo. When the connection is timed out, the client drops remaining messages in the buffer, even though they are marked as delivered.
### Execution
```bash
# Start the server
uv run server.py
```
```bash
# Start the client
uv run client.py
```
### Output
Server
```bash
#...
2023-12-04 10:03:37.557 | INFO | __main__:echo:26 - Sent message #1304
2023-12-04 10:03:37.581 | INFO | __main__:echo:26 - Sent message #1305
2023-12-04 10:03:37.604 | INFO | __main__:echo:26 - Sent message #1306
2023-12-04 10:04:05.961 | ERROR | __main__:echo:32 - Connection with client closed:
2023-12-04 10:04:05.961 | ERROR | __main__:echo:33 - no close frame received or sent
```
Client
```bash
#...
2023-12-04 10:04:15.039 | INFO | __main__:slow_processing:16 - Received message with 9,858 chars
2023-12-04 10:04:16.041 | INFO | __main__:slow_processing:16 - Received message with 10,303 chars
2023-12-04 10:04:17.042 | INFO | __main__:slow_processing:16 - Received message with 10,370 chars
2023-12-04 10:04:18.043 | ERROR | __main__:slow_processing:21 - Connection with server closed:
2023-12-04 10:04:18.044 | ERROR | __main__:slow_processing:22 - sent 1011 (internal error) keepalive ping timeout; no close frame received
```