A Python library for simplified network and HTTP connections management.
Project description
simple-sock
simple-sock offers a straightforward interface for TCP and UDP sockets in Python, with support for optional SSL/TLS encryption and routing for TCP connections.
Basic Usage
Basic TCP Server
from simple_sock import Server
app = Server()
@app.tcp_listen()
def handle_tcp(data):
print("Received:", data.msg)
return "Response from TCP server"
app.run("localhost", 5454) # Optional parameters: keyfile=None, certfile=None, timeout=0, buffer_size=1024
TCP Server with Routing
from simple_sock import Server
app = Server()
@app.parse_route
def parse_route(data):
return data.msg.split()[0]
@app.tcp_listen()
def default_route(data):
return "Default response"
@app.tcp_listen("route1")
def route1(data):
return "Response for route1"
app.run("localhost", 5454)
Basic TCP Client
from simple_sock import Client
client = Client()
client.connect("localhost", 5454) # Optional parameters: udp=False, tls=False
client.send("Hello from TCP client")
response = client.recv()
print(response)
client.close()
UDP Support
UDP usage is similar; use @app.udp_listen() for servers and set udp=True for clients. Example:
# UDP Server
app = Server(udp=True)
@app.udp_listen()
def handle_udp(data):
print("Received:", data.msg)
return "Response from UDP server"
app.run("localhost", 5455")
# UDP Client
client.connect("localhost", 5455, udp=True)
client.send("Hello from UDP client")
response, addr = client.recv()
print(response)
client.close()
License
MIT License
Contact
For questions, contact Leonardo Oliveira at email.
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_sock-0.1.4.tar.gz.
File metadata
- Download URL: simple_sock-0.1.4.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e8aa7de7bfa7434d8b53c31047ce9f0fdc9da7778a97c69439a6431d4150122
|
|
| MD5 |
80ddcd8201acdcfbf5b9b17663cac8dd
|
|
| BLAKE2b-256 |
017f9d167fc5e22ade4de2cb2c4e714578ecb0c36c2b23d2f33cad3d7e54244e
|
File details
Details for the file simple_sock-0.1.4-py3-none-any.whl.
File metadata
- Download URL: simple_sock-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc94345cb073ab1d5639f9174da0814b4a2cf035f5d51dd80be4931bb3dd4a52
|
|
| MD5 |
cf39fadb51b4ebb4e1f61e2ee1003c63
|
|
| BLAKE2b-256 |
e856f1eb9f2ea643d164ce78aeb7f3165c0762938200c078341b23488566fb68
|