A lightweight socket library
Project description
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
from cushy_socket.tcp import CushyTCPServer
es_tcp_server = CushyTCPServer(host='localhost', port=7777)
es_tcp_server.run()
@es_tcp_server.on_message()
def handle_msg_from_client(msg: str):
print(f"[server decorator callback] es_tcp_server rec msg: {msg}")
es_tcp_server.send("hello, I am server")
# echo tcp client program
from cushy_socket.tcp import CushyTCPClient
es_tcp_client = CushyTCPClient(host='localhost', port=7777)
es_tcp_client.run()
@es_tcp_client.on_message()
def handle_msg_from_server(msg: str):
print(f"[client decorator callback] es_tcp_client rec msg: {msg}")
es_tcp_client.send("hello, here is CSTCP client")
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.
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
cushy-socket-1.1.0.tar.gz
(8.5 kB
view hashes)