Skip to content

Once a naive CS student decided to implement WebSocket in python

Notifications You must be signed in to change notification settings

eszlamczyk/websocket-because-yes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

websocket-because-yes

This repository contains implementation of The WebSocket Protocol.

Necesarry liblaries:

Only numpy :) (tested on 1.26.4)

This repository contains:

  • 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)

Usage:

Demonstration:

Run server.py file:

python3 -m src.server

From (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:

  1. run server.py
python3 -m src.server
  1. from another terminal run test_client.py
python3 -m src.test_client
  1. 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:

Tests are implemented with unittest, to start them:

python3 -m unittest discover test -p "test_*.py"

About

Once a naive CS student decided to implement WebSocket in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages