Skip to main content
网络连接socket封装

支持心跳包, 支持长连接, 断线检测, 不粘包

测试代码:
if __name__ == '__main__':
import threading

from zsocket.commonlib.data_pack import data_pack
from zsocket.tcp.server import Server
from zsocket.tcp.client import Client


def server_client_connect_fun(client):
print('服务端收到连接', client.remote_addr)
server.close_listen()
threading.Thread(target=send_data, args=(client,)).start()


def server_client_close_fun(client, close_state):
print('服务端断开连接', client.remote_addr, close_state)


def send_data(client):
while client.is_connect:
text = input('请输入要发送的数据:')

if not client.is_connect:
return

if not text or text.lower() == 'q':
client.close()
return

client.send(text.encode())
client.send_text(text)
client.send_pack_arg(text, 1, 2, 3)


def client_connect_fun(client):
print('客户端连接', client.local_addr)


def client_close_fun(client, close_state):
print('客户端断开连接', client.local_addr, close_state)


def client_get_data_fun(client, data):
print('客户端收到数据', data)


def client_get_text_fun(client, text):
print('客户端收到文字', text)


def client_get_pack_fun(client, pack):
print('客户端收到包', pack.data, pack.a1, pack.a2, pack.a3)


server = Server()
server.password = '123'
server.set_client_connect_callback(server_client_connect_fun)
server.set_client_close_callback(server_client_close_fun)
server.listen(7777)

client = Client()
client.password = '123'
client.set_connect_callback(client_connect_fun)
client.set_close_callback(client_close_fun)
client.set_get_data_callback(client_get_data_fun)
client.set_get_text_callback(client_get_text_fun)
client.set_get_pack_callback(client_get_pack_fun)
client.connect('localhost', 7777)


Metadata

Release files for zsocket 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zsocket 1.0.3
File Size Uploaded Provenance Actions
zsocket-1.0.3.tar.gz 8.9 kB Without provenance Details for zsocket-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zsocket 1.0.3
File Interpreter ABI Platform Actions
zsocket-1.0.3-py3-none-any.whl Python 3 none any Details for zsocket-1.0.3-py3-none-any.whl

Total release size: 25.0 kB

Release files / zsocket-1.0.3.tar.gz

Download URL zsocket-1.0.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b6e461a68336fed0c3628b15306ab934584dac3a6e1202838c8b11faaf92d71c
BLAKE2b-256 checksum
How to use checksums
0a44d37fe79d0c9c7c80c57175dcda4c9630a8e036d8343634afe59101faf3c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Release files / zsocket-1.0.3-py3-none-any.whl

Download URL zsocket-1.0.3-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efb6ebcd214877c56832dc90aaf6ea53ad14ab5795e3992907cad42f4138d5c9
BLAKE2b-256 checksum
How to use checksums
e70f97df0cc47d1efa9ac0303f9d4382b0ee4fd2132bfffadb63cad15c364786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Security for zsocket 1.0.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page