This repository contains implementation of The WebSocket Protocol.
Only numpy :) (tested on 1.26.4)
- Basic server that listens on 127.0.0.1:5006 and can recievie data via WebSocket
- WebSocket class (that currently can recieve non-fragmented messages)
Run server.py file:
python3 -m src.serverFrom (for example) console in web browser connect to the server:
const socket = new WebSocket("ws://localhost:5006/websocket");Try sending messages to the server:
socket.send('test');
...
socket.send(125);The WebSocket also correctly interprets binary data:
socket.send(new Uint8Array([72, 101, 108, 108, 111]));The server very robustly logs connections and recieved messages :)
Other way to test the implementation is to use `test_client.py`
Usage:
- run
server.py
python3 -m src.server- from another terminal run test_client.py
python3 -m src.test_client- type in terminam any command:
- P <message up to 125B >-> ping
- C -> close connection
- T -> text message
- B <binary list of format
0-255,0-255,...> -> I think one could guess (send binarry message)
Tests are implemented with unittest, to start them:
python3 -m unittest discover test -p "test_*.py"