cushy-socket
A lightweight python socket library. You can create a TCP/UDP connection easily.
Features
- send socket message easily
- listen socket message and support ballback
- support sending group messages to clients
- support decorator version listening
- listen topic message and callback
Usage
pip install cushy-socket --upgrade
Here are some minimal example programs using the cushy-socket: a server that echoes all data that it receives back(servicing only one client), and a client using it.
- Now let's build a easy echo demo.The first example support IPv4 only.
# echo tcp server program
import socket
from cushy_socket.tcp import CushyTCPServer
cushy_tcp_server = CushyTCPServer(host='localhost', port=7777)
cushy_tcp_server.run()
@cushy_tcp_server.on_connected()
def handle_on_connected(sock: socket.socket):
print(f"[server decorator callback] new client connected.")
print(sock)
@cushy_tcp_server.on_disconnected()
def handle_on_disconnected(sock: socket.socket):
print(f"[server decorator callback] a client disconnected.")
print(sock)
@cushy_tcp_server.on_message()
def handle_msg_from_client(msg: str, socket: socket.socket):
print(f"[server decorator callback] cushy_tcp_server rec msg: {msg}")
cushy_tcp_server.send("hello, I am server")
# echo tcp client program
from cushy_socket.tcp import CushyTCPClient
cushy_tcp_client = CushyTCPClient(host='localhost', port=7777)
cushy_tcp_client.run()
@cushy_tcp_client.on_connected()
def handle_on_connected():
print(f"[client decorator callback] connect to server.")
@cushy_tcp_client.on_disconnected()
def handle_on_disconnected():
print(f"[client decorator callback] server disconnected.")
@cushy_tcp_client.on_message()
def handle_msg_from_server(msg: str):
print(f"[client decorator callback] cushy_tcp_client rec msg: {msg}")
cushy_tcp_client.send("hello, here is CSTCP client")
cushy_tcp_client.close()
TODO
- support for more lifecycle callbacks
- optimize the handle of socket closing
- optimize syntax expressions
- add UDP server/client support
- provide more solutions
- provide more async supports
- provide more decorator support
- optimize unittest
- send and listen topic message
Contribution
If you want to contribute to this project, you can submit pr or issue. I am glad to see more people involved and optimize it.
Metadata
Release files for cushy-socket 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cushy-socket-1.2.2.tar.gz | 8.9 kB | Without provenance | Details for cushy-socket-1.2.2.tar.gz |
Release files / cushy-socket-1.2.2.tar.gz
| Download URL | cushy-socket-1.2.2.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85de3658757bf18a87be727e2d9992e782757050d59bcd823d1965e832897b3f
|
|
BLAKE2b-256 checksum How to use checksums |
d3dc5a0719f6364f9c87a2eb45ec687069a0577834ec05bad0466a678af9c730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|
Security for cushy-socket 1.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.