A lightweight Python WebSocket test server for monitoring and testing WebSocket handshakes.
Supports both ws:// and wss:// protocols with optional Basic Auth.
- Simultaneous
ws://andwss://support - Detailed handshake logging (headers, auth, connect/disconnect, incoming messages)
- Basic Auth (enable/disable via flag)
- Auto-generated self-signed certificate (no OpenSSL required)
- Logs to console and
ws_server.log
- Python 3.9+
websockets13+ andcryptography(seerequirements.txt)
pip install -r requirements.txtpython main.py [--ws | --wss | --both] [--no-auth] [--host ADDR]| Parameters | Result |
|---|---|
| (empty) | both ports, auth ON |
--ws |
ws:// only, auth ON |
--wss |
wss:// only, auth ON |
--both |
both ports, auth ON |
--no-auth |
both ports, auth OFF |
--ws --no-auth |
ws:// only, auth OFF |
--wss --no-auth |
wss:// only, auth OFF |
--host 127.0.0.1 |
listen on localhost only (default 0.0.0.0 = all interfaces) |
| Protocol | Address |
|---|---|
| WS | ws://localhost:8765 |
| WSS | wss://localhost:8766 |
Ports can be changed via WS_PORT / WSS_PORT at the top of main.py.
Uses HTTP Basic Auth (Authorization: Basic <base64(user:password)>).
Edit the USERS dict in main.py to add/change credentials. The default
users (admin / secret, test / 1234) are for testing only.
The handshake itself is accepted; if the credentials are missing or wrong,
the server closes the connection right away with code 1008 Unauthorized.
Example with websocat (YWRtaW46c2VjcmV0 = admin:secret):
websocat -H "Authorization: Basic YWRtaW46c2VjcmV0" ws://localhost:8765- WSS uses a self-signed certificate (
cert.pem/key.pem, generated on first run, valid 365 days) — clients must ignore certificate verification. Delete both files to regenerate. - Server sends
OKimmediately after a successful handshake (for response time monitoring) - Incoming text/binary messages are logged (first 240 characters/bytes), not answered
- All activity is logged to
ws_server.login the working directory
This is a testing tool, not a production server. It listens on all interfaces
by default and ships with well-known demo credentials — use --host 127.0.0.1
or a firewall if the machine is reachable from untrusted networks.