一个 socket 模块
Project description
gsocket
一个仅 Python 使用的基于 socket 协议的模块
- SocketServer:连接服务端
- SocketClient:连接客户端
- SocketReceiver:自定义 on_open 等
注意:
- SocketServer、SocketClient、SocketReceiver 自带 send、sendall、sendfile 方法
- 本模块未匹配 websocket 协议,所有通信基于 struct 防止粘包,所以不适用
安装
pip install gsocket
SocketServer
from gsocket import SocketServer
SocketServer().start_server()
SocketClient
推荐使用 with 上下文,不然需要手动关闭
from gsocket import SocketClient
with SocketClient() as s:
s.send(msg="你好")
SocketReceiver
SocketServer、SocketClient 都具备此参数,可以自由定义其接收方法 下面以 SocketServer 示例
from typing import Generator
from gsocket import SocketServer, SocketReceiver
class MySocketReceiver(SocketReceiver):
def on_open(self):
pass
def on_message(self, msg: bytes):
pass
def on_file(self, filename: str, file_iterator: Generator):
pass
def on_close(self):
pass
SocketServer(receiver=MySocketReceiver).start_server()
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
gsocket-0.0.2.tar.gz
(6.5 kB
view details)
File details
Details for the file gsocket-0.0.2.tar.gz
.
File metadata
- Download URL: gsocket-0.0.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace69800f0b0e1bc801f5faf3a7554dd0acb5bf15ab690e7c9e8aa45388dca8f |
|
MD5 | 3bb5b297d93ede86d1be253dc165e820 |
|
BLAKE2b-256 | 5e1c69531c5256b0b542a0e11ac66ba3e2eac040277f3086f9f9567f89ab34dd |