Simple TCP server/client framework.
Project description
simple_tcp_server
Simple TCP server framework.
Installation
pip install simple_tcp_server
Usage
from simple_tcp_server import SimpleTcpServer, SimpleTcpClient
import threading
import time
HOST = "127.0.0.1"
PORT = 9999
def is_prime(msg: bytes) -> bytes:
n = int(msg.decode())
if n < 2:
return b"$"
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return b"$"
return b"$$"
server = SimpleTcpServer(HOST, PORT, is_prime, quit_token=b"quit")
t = threading.Thread(target=server.mainloop, daemon=True)
t.start()
time.sleep(0.2)
client = SimpleTcpClient(HOST, PORT)
numbers = [b"2", b"10", b"17", b"97", b"1234567"]
for n in numbers:
res = client.request(n)
print(f"{n}: {res}")
# close server by quit_token
client.request(b"quit")
for n in numbers:
res = client.request(n)
print(f"{n}: {res}")
client.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_tcp_server-0.1.1.tar.gz.
File metadata
- Download URL: simple_tcp_server-0.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.13.12 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37a3a48d6baf7e1dfd7c3e545b6d73f148b04bede16ceb55eb68f635eac24bf0
|
|
| MD5 |
e9e5f4f076cc16aafd5819932cf2413e
|
|
| BLAKE2b-256 |
b742c1b5499a62e9a2e583c75ff2dbe11d50d38014b7d93cbf72c045f8b84ae0
|
File details
Details for the file simple_tcp_server-0.1.1-py3-none-any.whl.
File metadata
- Download URL: simple_tcp_server-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.13.12 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce635a64b74261182421a3c28daef15a3521c38ac8ebe2018cc9be2154f9c57b
|
|
| MD5 |
26d7f0ec07c87e3e3268a952aa72a60b
|
|
| BLAKE2b-256 |
c1bcef56ab7dee30732d046d54097cceb51303967221fb80257999d3da5c3925
|