Skip to main content

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")
server.set_debug_mode(True) # default is False
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)

# close server by quit_token
client.request(b"quit")
for n in numbers:
    res = client.request(n)

client.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_tcp_server-0.1.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_tcp_server-0.1.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_tcp_server-0.1.2.tar.gz.

File metadata

  • Download URL: simple_tcp_server-0.1.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.12 Windows/11

File hashes

Hashes for simple_tcp_server-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0115c2ab3348cd252f1dfaef2e0315e7b20f6290997619d139c79596939d345b
MD5 9808b1e7dacf07a2cf722ec969cc0b32
BLAKE2b-256 4a497b8e8945143119c4220dd3399423d539c15d3d1a947c9df73e96ed2c7d15

See more details on using hashes here.

File details

Details for the file simple_tcp_server-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: simple_tcp_server-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.12 Windows/11

File hashes

Hashes for simple_tcp_server-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eee74ea5334e46a32223332d673eecf762f8692f531a364643836eb1697d72bb
MD5 f9ba7f5fed617de94273d548ceca81e8
BLAKE2b-256 053577b5cf81423bd84b4071cf40a0884979bdc73360ee0dcdc18a50eb60b4ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page