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.3.tar.gz
(4.1 kB
view details)
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 suef-simpletcp-0.0.3.tar.gz.
File metadata
- Download URL: suef-simpletcp-0.0.3.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874d53fbed9381bc4f1fdf23b4e4a8b556558dea48eebf2128f689368c23c17d
|
|
| MD5 |
337f1ea25a44535ffee3652d345fc179
|
|
| BLAKE2b-256 |
3c680e6be6149b6cd0c1de7024a1d027ed4c91c42a4de8c267a2280b1c71167e
|
File details
Details for the file suef_simpletcp-0.0.3-py3-none-any.whl.
File metadata
- Download URL: suef_simpletcp-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5409db072d803f2351397568cf7c656de66bdeae9aebe7fd4d30b170c3b8b484
|
|
| MD5 |
4e21c2f1baabdc3c4bac247b2002e6ea
|
|
| BLAKE2b-256 |
d85f457b98a3d329e7fc012bfeb49c9e0a1373c8059d5630019fe891da842996
|