Skip to content

zluuba/udp-server-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple UDP Server (Python)

Simple UDP server that can receive TLV-scheme data with a bunch of commands.
Single-threaded, blocking I/O (for now).

Requirements

You only need to have Python installed (version 3.11 or higher).
You can download it here.

Installation / Running

Open a terminal window. Clone this repository (with Git) or download it with Pip:

git clone https://github.com/zluuba/udp_tlv_server.git
pip install --user git+https://github.com/zluuba/udp_tlv_server.git

Navigate to the udp_tlv_server/python:

cd udp_tlv_server/python

Run the server:

make server

Run the client (or use netcat/nc):

make client

Testing

Data for testing

# valid. tag: 0x0, value: 1
echo -ne '\x00\x00\x00\x00\x00\x00\x00\x011' | nc -u -w1 127.0.0.1 31337

# valid. tag: 0x1, value: 42
echo -ne '\x00\x00\x00\x01\x00\x00\x00\x0242' | nc -u -w1 127.0.0.1 31337

# two commands: valid
echo -ne '\x00\x00\x00\x00\x00\x00\x00\x011\x00\x00\x00\x01\x00\x00\x00\x0242' | nc -u -w1 127.0.0.1 31337

# two commands: valid and invalid
echo -ne '\x00\x00\x00\x01\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00\x00\x018' | nc -u -w1 127.0.0.1 31337

# invalid command: unknown tag. tag: 0x3, value: 0
echo -ne '\x00\x00\x00\x03\x00\x00\x00\x010' | nc -u -w1 127.0.0.1 31337

# invalid command: invalid value. tag: 0x0, value: 8
echo -ne '\x00\x00\x00\x00\x00\x00\x00\x018' | nc -u -w1 127.0.0.1 31337

# incorrect TLV scheme
echo -ne 'linuswouldbescreamingifhesawthis' | nc -u -w1 127.0.0.1 31337

Additional

You can check project with tests, linter and typing checker.
You need pytest, flake8 and mypy to be installed (better be installing them in venv):

make install-dev-dep

To run all checks (tests, linter, typing checks, test coverage) run the following command:

make check

Or run checks separately:

make test
make lint
make typing
make test-coverage