Skip to main content

Simple solution to get started with TCP Servers and Clients

Project description

TCP

This repository contains simplefied classes to use TCP sockets much easier.

Usage

from multiprocessing import Process
from suef_simpletcp import Server, Client
from suef_simpletcp import BaseConnection

class MyServer(Server):
    def onClientConnect(self, client: BaseConnection):
        while True:
            try:
                if client.get().lower() == 'ping':
                    client.send('Pong!')
            except KeyboardInterrupt:
                pass
    
    def onClientDisconnect(self, client: BaseConnection, error: Exception):
        print(f'Connection to Client (ip: {client.ip}, port: {client.port}) got interrupted. Reason: {error.__class__.__name__}')

if __name__ == "__main__":
    # running server in different process, because it blocks further code execution (it's not asynchronous)
    server = MyServer('127.0.0.1', 1074)
    serverProcess = Process(target=server.start, args=())
    serverProcess.start()


    with Client('127.0.0.1', 1074) as client:
        client.send('ping')
        print(client.get()) # output: Pong!
    serverProcess.terminate()

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

suef-simpletcp-0.0.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

suef_simpletcp-0.0.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file suef-simpletcp-0.0.4.tar.gz.

File metadata

  • Download URL: suef-simpletcp-0.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.6

File hashes

Hashes for suef-simpletcp-0.0.4.tar.gz
Algorithm Hash digest
SHA256 58a307eacf357dfae3798dafd70d72eb2000551a972d8a89cb47ffefbb1ab984
MD5 55de2d3bab908f51d27ab306e0668cdf
BLAKE2b-256 f25ba6e3e0f99e5ab00db12b61403c35274aa294ab9206951e1e25d56aab994f

See more details on using hashes here.

File details

Details for the file suef_simpletcp-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: suef_simpletcp-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.6

File hashes

Hashes for suef_simpletcp-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 26bf7de81f9fde6c838cdc53c5d21b9d9d3036dd412d276830acb41fa2edb801
MD5 6763f5380729d0aee86303fbdce78130
BLAKE2b-256 9d79e92634abae9b130fda33208150ab3e110a252796000bcffe397afa5f879e

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