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


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.1.tar.gz (4.9 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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for simple_tcp_server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 37a3a48d6baf7e1dfd7c3e545b6d73f148b04bede16ceb55eb68f635eac24bf0
MD5 e9e5f4f076cc16aafd5819932cf2413e
BLAKE2b-256 b742c1b5499a62e9a2e583c75ff2dbe11d50d38014b7d93cbf72c045f8b84ae0

See more details on using hashes here.

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

Hashes for simple_tcp_server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce635a64b74261182421a3c28daef15a3521c38ac8ebe2018cc9be2154f9c57b
MD5 26d7f0ec07c87e3e3268a952aa72a60b
BLAKE2b-256 c1bcef56ab7dee30732d046d54097cceb51303967221fb80257999d3da5c3925

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