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()
Metadata
Release files for gsocket 0.0.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 |
|---|---|---|---|---|
| gsocket-0.0.2.tar.gz | 6.5 kB | Without provenance | Details for gsocket-0.0.2.tar.gz |
Release files / gsocket-0.0.2.tar.gz
| Download URL | gsocket-0.0.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ace69800f0b0e1bc801f5faf3a7554dd0acb5bf15ab690e7c9e8aa45388dca8f
|
|
BLAKE2b-256 checksum How to use checksums |
5e1c69531c5256b0b542a0e11ac66ba3e2eac040277f3086f9f9567f89ab34dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.2
|
Security for gsocket 0.0.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.