litenetlib-0952 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- litenetlib/__init__.py +66 -0
- litenetlib/channels/__init__.py +16 -0
- litenetlib/channels/base_channel.py +115 -0
- litenetlib/channels/reliable_channel.py +451 -0
- litenetlib/channels/sequenced_channel.py +239 -0
- litenetlib/core/__init__.py +53 -0
- litenetlib/core/connection_request.py +240 -0
- litenetlib/core/constants.py +186 -0
- litenetlib/core/events.py +336 -0
- litenetlib/core/internal_packets.py +358 -0
- litenetlib/core/manager.py +355 -0
- litenetlib/core/packet.py +457 -0
- litenetlib/core/peer.py +334 -0
- litenetlib/utils/__init__.py +21 -0
- litenetlib/utils/data_reader.py +447 -0
- litenetlib/utils/data_writer.py +402 -0
- litenetlib/utils/fast_bit_converter.py +199 -0
- litenetlib/utils/net_utils.py +165 -0
- litenetlib_0952-1.0.0.dist-info/METADATA +448 -0
- litenetlib_0952-1.0.0.dist-info/RECORD +23 -0
- litenetlib_0952-1.0.0.dist-info/WHEEL +5 -0
- litenetlib_0952-1.0.0.dist-info/licenses/LICENSE +21 -0
- litenetlib_0952-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Network utility functions for LiteNetLib v0.9.5.2 / LiteNetLib 网络工具函数
|
|
3
|
+
|
|
4
|
+
Ported from: LiteNetLib/Utils/NetUtils.cs
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import time
|
|
8
|
+
import random
|
|
9
|
+
from litenetlib.core.constants import NetConstants
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class NetUtils:
|
|
13
|
+
"""
|
|
14
|
+
Utility functions for network operations / 网络操作工具函数
|
|
15
|
+
|
|
16
|
+
Ported from C# NetUtils class.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def relative_sequence_number(number: int, expected: int) -> int:
|
|
21
|
+
"""
|
|
22
|
+
Calculate relative sequence number considering wrap-around.
|
|
23
|
+
计算相对序列号,考虑循环回绕。
|
|
24
|
+
|
|
25
|
+
Ported from C# implementation:
|
|
26
|
+
RelativeSequenceNumber(int number, int expected)
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
number: The sequence number to evaluate / 要评估的序列号
|
|
30
|
+
expected: The reference/expected sequence number / 参考/期望的序列号
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Relative distance (can be negative for wrap-around)
|
|
34
|
+
相对距离(循环回绕时可以为负)
|
|
35
|
+
|
|
36
|
+
C# Formula:
|
|
37
|
+
(number - expected + MaxSequence + HalfMaxSequence) % MaxSequence - HalfMaxSequence
|
|
38
|
+
"""
|
|
39
|
+
# C#: (number - expected + MaxSequence + HalfMaxSequence) % MaxSequence - HalfMaxSequence
|
|
40
|
+
return (number - expected + NetConstants.MAX_SEQUENCE + NetConstants.HALF_MAX_SEQUENCE) % NetConstants.MAX_SEQUENCE - NetConstants.HALF_MAX_SEQUENCE
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def is_sequence_less_than(s1: int, s2: int) -> bool:
|
|
44
|
+
"""
|
|
45
|
+
Check if s1 < s2 considering sequence wrap-around.
|
|
46
|
+
检查 s1 是否小于 s2(考虑序列号循环)。
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
s1: First sequence number / 第一个序列号
|
|
50
|
+
s2: Second sequence number / 第二个序列号
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
True if s1 < s2 in circular sense / 在循环意义上 s1 < s2 时返回 True
|
|
54
|
+
"""
|
|
55
|
+
return NetUtils.relative_sequence_number(s1, s2) < 0
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def is_sequence_greater_than(s1: int, s2: int) -> bool:
|
|
59
|
+
"""
|
|
60
|
+
Check if s1 > s2 considering sequence wrap-around.
|
|
61
|
+
检查 s1 是否大于 s2(考虑序列号循环)。
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
s1: First sequence number / 第一个序列号
|
|
65
|
+
s2: Second sequence number / 第二个序列号
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
True if s1 > s2 in circular sense / 在循环意义上 s1 > s2 时返回 True
|
|
69
|
+
"""
|
|
70
|
+
return NetUtils.relative_sequence_number(s1, s2) > 0
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def get_time_millis() -> int:
|
|
74
|
+
"""
|
|
75
|
+
Get current time in milliseconds.
|
|
76
|
+
获取当前时间(毫秒)。
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Current time in milliseconds / 当前毫秒时间戳
|
|
80
|
+
"""
|
|
81
|
+
return int(time.time() * 1000)
|
|
82
|
+
|
|
83
|
+
@staticmethod
|
|
84
|
+
def get_time_ticks() -> int:
|
|
85
|
+
"""
|
|
86
|
+
Get current time in ticks (100ns units).
|
|
87
|
+
获取当前时间(刻度,100ns 单位)。
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Current time in ticks / 当前刻度时间戳
|
|
91
|
+
"""
|
|
92
|
+
return int(time.time() * 10000000)
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def random_bytes(length: int) -> bytes:
|
|
96
|
+
"""
|
|
97
|
+
Generate random bytes.
|
|
98
|
+
生成随机字节。
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
length: Number of bytes to generate / 要生成的字节数
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Random bytes / 随机字节
|
|
105
|
+
"""
|
|
106
|
+
return bytes(random.getrandbits(8) for _ in range(length))
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def generate_connect_id() -> int:
|
|
110
|
+
"""
|
|
111
|
+
Generate a random connection ID.
|
|
112
|
+
生成随机连接 ID。
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Random connection ID / 随机连接 ID
|
|
116
|
+
"""
|
|
117
|
+
return random.randint(0, 0xFFFFFFFF)
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def parse_address(address: str) -> tuple:
|
|
121
|
+
"""
|
|
122
|
+
Parse address string into host and port.
|
|
123
|
+
将地址字符串解析为主机和端口。
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
address: Address string (e.g., "127.0.0.1:7777" or "[::1]:7777")
|
|
127
|
+
地址字符串(例如 "127.0.0.1:7777" 或 "[::1]:7777")
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Tuple of (host, port) / (主机, 端口) 元组
|
|
131
|
+
"""
|
|
132
|
+
if address.startswith('['):
|
|
133
|
+
# IPv6
|
|
134
|
+
if ']:' in address:
|
|
135
|
+
# Split on the last ']:' to separate host from port
|
|
136
|
+
parts = address.rsplit(']:', 1)
|
|
137
|
+
host = parts[0][1:] # Remove opening bracket
|
|
138
|
+
port = int(parts[1]) if len(parts) > 1 else None
|
|
139
|
+
return host, port
|
|
140
|
+
# No port, just remove brackets
|
|
141
|
+
return address[1:-1], None
|
|
142
|
+
else:
|
|
143
|
+
# IPv4
|
|
144
|
+
parts = address.rsplit(':', 1)
|
|
145
|
+
if len(parts) == 2:
|
|
146
|
+
return parts[0], int(parts[1])
|
|
147
|
+
return parts[0], None
|
|
148
|
+
|
|
149
|
+
@staticmethod
|
|
150
|
+
def format_address(host: str, port: int) -> str:
|
|
151
|
+
"""
|
|
152
|
+
Format host and port into address string.
|
|
153
|
+
将主机和端口格式化为地址字符串。
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
host: Host address / 主机地址
|
|
157
|
+
port: Port number / 端口号
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
Formatted address string / 格式化的地址字符串
|
|
161
|
+
"""
|
|
162
|
+
if ':' in host:
|
|
163
|
+
# IPv6
|
|
164
|
+
return f"[{host}]:{port}"
|
|
165
|
+
return f"{host}:{port}"
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: litenetlib-0952
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Lite reliable UDP networking library for Python (C# LiteNetLib v0.9.5.2 compatible)
|
|
5
|
+
Home-page: https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2
|
|
6
|
+
Author: xiaoyanghuo
|
|
7
|
+
Author-email:
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2
|
|
10
|
+
Project-URL: Documentation, https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2/blob/main/README.md
|
|
11
|
+
Project-URL: Repository, https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2/issues
|
|
13
|
+
Keywords: networking,udp,reliable,protocol,litenetlib,game,networking
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Topic :: System :: Networking
|
|
27
|
+
Requires-Python: >=3.7
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == "dev"
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
|
|
37
|
+
# litenetlib-0952
|
|
38
|
+
|
|
39
|
+
**LiteNetLib v0.9.5.2 的 Python 实现**
|
|
40
|
+
|
|
41
|
+
[](https://www.python.org/downloads/)
|
|
42
|
+
[](LICENSE)
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 简介
|
|
47
|
+
|
|
48
|
+
`litenetlib-0952` 是一个轻量级可靠的 UDP 网络库,为 Python 提供 C# LiteNetLib v0.9.5.2 的功能。本项目是从 C# 原版移植而来的第三方实现,专注于提供与原版 v0.9.5.2 完全二进制兼容的 Python 接口。
|
|
49
|
+
|
|
50
|
+
### 主要特点
|
|
51
|
+
|
|
52
|
+
- **100% 二进制兼容**:与 C# LiteNetLib v0.9.5.2 协议完全兼容
|
|
53
|
+
- **可靠传输**:支持 ACK、重传、顺序保证
|
|
54
|
+
- **分片传输**:大数据包自动分片重组
|
|
55
|
+
- **多种传输模式**:5 种传输方法满足不同需求
|
|
56
|
+
- **UTF-8 支持**:完整支持中文等 Unicode 字符
|
|
57
|
+
- **纯 Python**:无外部依赖,易于集成
|
|
58
|
+
|
|
59
|
+
### 适用场景
|
|
60
|
+
|
|
61
|
+
- 游戏网络同步
|
|
62
|
+
- 实时通信应用
|
|
63
|
+
- 需要可靠 UDP 传输的场景
|
|
64
|
+
- Python 与 C# 服务器的互通
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 安装
|
|
69
|
+
|
|
70
|
+
### 从 PyPI 安装(推荐)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install litenetlib-0952
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 从源码安装
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
git clone https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2.git
|
|
80
|
+
cd LiteNetLib-Python-0.9.5.2
|
|
81
|
+
pip install .
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 系统要求
|
|
85
|
+
|
|
86
|
+
- Python 3.7+
|
|
87
|
+
- asyncio 支持(Python 3.7+ 内置)
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 快速开始
|
|
92
|
+
|
|
93
|
+
### Echo 服务器
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import asyncio
|
|
97
|
+
from litenetlib import LiteNetManager, EventBasedNetListener
|
|
98
|
+
|
|
99
|
+
async def main():
|
|
100
|
+
listener = EventBasedNetListener()
|
|
101
|
+
|
|
102
|
+
@listener.on_peer_connected
|
|
103
|
+
def on_peer_connected(peer):
|
|
104
|
+
print(f"Client connected: {peer.address}")
|
|
105
|
+
|
|
106
|
+
@listener.on_network_receive
|
|
107
|
+
def on_receive(peer, reader, channel_id, delivery_method):
|
|
108
|
+
data = reader.get_remaining_bytes()
|
|
109
|
+
print(f"Received: {data}")
|
|
110
|
+
peer.send(data, delivery_method)
|
|
111
|
+
|
|
112
|
+
manager = LiteNetManager(listener)
|
|
113
|
+
manager.start(9050) # 监听端口 9050
|
|
114
|
+
|
|
115
|
+
print("Server started on port 9050")
|
|
116
|
+
|
|
117
|
+
while True:
|
|
118
|
+
manager.poll()
|
|
119
|
+
await asyncio.sleep(0.015)
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
asyncio.run(main())
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Echo 客户端
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
import asyncio
|
|
129
|
+
from litenetlib import LiteNetManager, EventBasedNetListener
|
|
130
|
+
from litenetlib.utils.data_writer import NetDataWriter
|
|
131
|
+
from litenetlib.core.constants import DeliveryMethod
|
|
132
|
+
|
|
133
|
+
async def main():
|
|
134
|
+
listener = EventBasedNetListener()
|
|
135
|
+
manager = LiteNetManager(listener)
|
|
136
|
+
|
|
137
|
+
@listener.on_peer_connected
|
|
138
|
+
def on_connected(peer):
|
|
139
|
+
print(f"Connected to server: {peer.address}")
|
|
140
|
+
# 发送消息
|
|
141
|
+
writer = NetDataWriter()
|
|
142
|
+
writer.put_string("Hello from Python!")
|
|
143
|
+
peer.send(writer.data, DeliveryMethod.RELIABLE_ORDERED)
|
|
144
|
+
|
|
145
|
+
manager.connect("127.0.0.1", 9050)
|
|
146
|
+
|
|
147
|
+
while True:
|
|
148
|
+
manager.poll()
|
|
149
|
+
await asyncio.sleep(0.015)
|
|
150
|
+
|
|
151
|
+
if __name__ == "__main__":
|
|
152
|
+
asyncio.run(main())
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 核心功能
|
|
158
|
+
|
|
159
|
+
### 1. 传输方法
|
|
160
|
+
|
|
161
|
+
| 方法 | 说明 | 用途 |
|
|
162
|
+
|------|------|------|
|
|
163
|
+
| `UNRELIABLE` | 不可靠传输 | 位置更新、频繁数据 |
|
|
164
|
+
| `RELIABLE_UNORDERED` | 可靠无序 | 重要数据、状态同步 |
|
|
165
|
+
| `SEQUENCED` | 有序传递 | 最新状态 |
|
|
166
|
+
| `RELIABLE_ORDERED` | 可靠有序 | 必须按顺序的数据 |
|
|
167
|
+
| `RELIABLE_SEQUENCED` | 可靠有序 | 有序的重要数据 |
|
|
168
|
+
|
|
169
|
+
### 2. 数据包类型
|
|
170
|
+
|
|
171
|
+
支持 18 种数据包类型:
|
|
172
|
+
|
|
173
|
+
- `UNRELIABLE` - 不可靠数据
|
|
174
|
+
- `CHANNELED` - 通道数据(带序列号)
|
|
175
|
+
- `ACK` - 确认包
|
|
176
|
+
- `PING/PONG` - 心跳包
|
|
177
|
+
- `CONNECT_REQUEST/ACCEPT` - 连接请求/接受
|
|
178
|
+
- `DISCONNECT` - 断开连接
|
|
179
|
+
- `MERGED` - 合并包(提高效率)
|
|
180
|
+
- `MTU_CHECK/OK` - MTU 发现
|
|
181
|
+
- 等等...
|
|
182
|
+
|
|
183
|
+
### 3. 协议特性
|
|
184
|
+
|
|
185
|
+
**协议常量**:
|
|
186
|
+
- `PROTOCOL_ID = 11`(v0.9.5.2)
|
|
187
|
+
- `DEFAULT_WINDOW_SIZE = 64`
|
|
188
|
+
- `MAX_SEQUENCE = 32768`
|
|
189
|
+
|
|
190
|
+
**数据包格式**:
|
|
191
|
+
- 小端字节序(Little-Endian)
|
|
192
|
+
- UTF-8 字符串编码
|
|
193
|
+
- 自动分片(MTU 通常为 1400 字节)
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## C# / Python 互操作
|
|
198
|
+
|
|
199
|
+
本项目与 C# LiteNetLib v0.9.5.2 完全兼容,可以实现:
|
|
200
|
+
|
|
201
|
+
### Python 客户端 ↔ C# 服务器
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
# Python 客户端连接到 C# 服务器
|
|
205
|
+
manager.connect("csharp_server_ip", 9050)
|
|
206
|
+
# 数据格式完全兼容
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Python 服务器 ↔ C# 客户端
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
# Python 服务器接收 C# 客户端连接
|
|
213
|
+
manager.start(9050)
|
|
214
|
+
# 自动处理 C# 客户端的连接请求
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 二进制兼容性验证
|
|
218
|
+
|
|
219
|
+
所有协议层均已验证:
|
|
220
|
+
- ✅ 协议常量一致
|
|
221
|
+
- ✅ 数据包格式一致
|
|
222
|
+
- ✅ 序列化格式一致
|
|
223
|
+
- ✅ ACK/重传机制一致
|
|
224
|
+
|
|
225
|
+
详细验证结果请参考:[INTEROPERABILITY_TEST_REPORT.md](INTEROPERABILITY_TEST_REPORT.md)
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## API 文档
|
|
230
|
+
|
|
231
|
+
### 创建管理器
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
from litenetlib import LiteNetManager, EventBasedNetListener
|
|
235
|
+
|
|
236
|
+
listener = EventBasedNetListener()
|
|
237
|
+
manager = LiteNetManager(listener)
|
|
238
|
+
manager.start(9050)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 连接到服务器
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
peer = manager.connect("127.0.0.1", 9050, "connection_key")
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 发送数据
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from litenetlib.utils.data_writer import NetDataWriter
|
|
251
|
+
from litenetlib.core.constants import DeliveryMethod
|
|
252
|
+
|
|
253
|
+
writer = NetDataWriter()
|
|
254
|
+
writer.put_string("Hello")
|
|
255
|
+
writer.put_int(12345)
|
|
256
|
+
|
|
257
|
+
peer.send(writer.data, DeliveryMethod.RELIABLE_ORDERED)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### 接收数据
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
@listener.on_network_receive
|
|
264
|
+
def on_receive(peer, reader, channel_id, delivery_method):
|
|
265
|
+
msg = reader.get_string()
|
|
266
|
+
num = reader.get_int()
|
|
267
|
+
data = reader.get_remaining_bytes()
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 示例
|
|
273
|
+
|
|
274
|
+
完整示例代码请参考 `examples/` 目录:
|
|
275
|
+
|
|
276
|
+
- `echo_server.py` - Echo 服务器
|
|
277
|
+
- `echo_client.py` - Echo 客户端
|
|
278
|
+
|
|
279
|
+
运行示例:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Terminal 1: 启动服务器
|
|
283
|
+
python examples/echo_server.py
|
|
284
|
+
|
|
285
|
+
# Terminal 2: 启动客户端
|
|
286
|
+
python examples/echo_client.py
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 测试
|
|
292
|
+
|
|
293
|
+
运行测试套件:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
# 克隆仓库
|
|
297
|
+
git clone https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2.git
|
|
298
|
+
cd LiteNetLib-Python-0.9.5.2
|
|
299
|
+
|
|
300
|
+
# 安装
|
|
301
|
+
pip install .
|
|
302
|
+
|
|
303
|
+
# 运行测试
|
|
304
|
+
python -m pytest tests/ -v
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
测试结果:
|
|
308
|
+
- 单元测试:365/365 通过(100%)
|
|
309
|
+
- 核心功能测试:100% 通过
|
|
310
|
+
- 协议兼容性:100% 通过
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## 原作者与致谢
|
|
315
|
+
|
|
316
|
+
### C# 原版 LiteNetLib
|
|
317
|
+
|
|
318
|
+
本项目移植自 C# 版本的 LiteNetLib v0.9.5.2。
|
|
319
|
+
|
|
320
|
+
- **原作者**:RevenantX (Hubert "LHub" Tonneau)
|
|
321
|
+
- **原版仓库**:https://github.com/RevenantX/LiteNetLib
|
|
322
|
+
- **版本**:v0.9.5.2
|
|
323
|
+
|
|
324
|
+
### 移植说明
|
|
325
|
+
|
|
326
|
+
本项目是 LiteNetLib v0.9.5.2 的**非官方 Python 移植版本**,由社区贡献者维护。
|
|
327
|
+
|
|
328
|
+
移植过程中:
|
|
329
|
+
- 保持了与原版 v0.9.5.2 的协议兼容性
|
|
330
|
+
- 使用 Python asyncio 实现异步 I/O
|
|
331
|
+
- 适配 Python 编码风格
|
|
332
|
+
- 添加 Python 生态的集成(pytest、pip 等)
|
|
333
|
+
|
|
334
|
+
### 开源协议
|
|
335
|
+
|
|
336
|
+
本项目采用 MIT 许可证开源,与原版 C# LiteNetLib 保持一致。
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## 许可证
|
|
341
|
+
|
|
342
|
+
MIT License
|
|
343
|
+
|
|
344
|
+
Copyright (c) 2026 xiaoyanghuo
|
|
345
|
+
|
|
346
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
347
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
348
|
+
in the Software without restriction, including without limitation the rights
|
|
349
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
350
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
351
|
+
furnished to do so, subject to the following conditions:
|
|
352
|
+
|
|
353
|
+
The above copyright notice and this permission notice shall be included in all
|
|
354
|
+
copies or substantial portions of the Software.
|
|
355
|
+
|
|
356
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
357
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
358
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
359
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
360
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
361
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
362
|
+
SOFTWARE.
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## 项目信息
|
|
367
|
+
|
|
368
|
+
- **包名**:`litenetlib-0952`
|
|
369
|
+
- **版本**:1.0.0
|
|
370
|
+
- **兼容 C# 版本**:LiteNetLib v0.9.5.2
|
|
371
|
+
- **Python 要求**:>= 3.7
|
|
372
|
+
- **许可**:MIT
|
|
373
|
+
|
|
374
|
+
## 链接
|
|
375
|
+
|
|
376
|
+
- **GitHub**:https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2
|
|
377
|
+
- **PyPI**:https://pypi.org/project/litenlib-0952/
|
|
378
|
+
- **问题反馈**:https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2/issues
|
|
379
|
+
- **原版 C#**:https://github.com/RevenantX/LiteNetLib
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
## 常见问题
|
|
384
|
+
|
|
385
|
+
### Q: 与 C# 版本的关系?
|
|
386
|
+
|
|
387
|
+
A: 本项目是 C# LiteNetLib v0.9.5.2 的 Python 移植版本,协议层 100% 兼容。可以将 Python 客户端连接到 C# 服务器,反之亦然。
|
|
388
|
+
|
|
389
|
+
### Q: 支持哪些 Python 版本?
|
|
390
|
+
|
|
391
|
+
A: Python 3.7 及以上版本。
|
|
392
|
+
|
|
393
|
+
### Q: 需要外部依赖吗?
|
|
394
|
+
|
|
395
|
+
A: 不需要。本项目是纯 Python 实现,无外部依赖。
|
|
396
|
+
|
|
397
|
+
### Q: 性能如何?
|
|
398
|
+
|
|
399
|
+
A: 对于大多数应用场景,性能足够。如果需要极致性能,建议使用原 C# 版本。
|
|
400
|
+
|
|
401
|
+
### Q: 与其他 Python 网络库的区别?
|
|
402
|
+
|
|
403
|
+
A: 本项目专注于与 C# LiteNetLib v0.9.5.2 的互操作性,适合需要 C#/Python 混合部署的场景。
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## 更新日志
|
|
408
|
+
|
|
409
|
+
### v1.0.0 (2026-02-03)
|
|
410
|
+
|
|
411
|
+
初始发布,功能包括:
|
|
412
|
+
- 完整的协议实现(18 种数据包类型)
|
|
413
|
+
- 5 种传输方法
|
|
414
|
+
- ACK/重传机制
|
|
415
|
+
- 分片包传输
|
|
416
|
+
- MERGED 包处理
|
|
417
|
+
- UTF-8 字符串支持(包括中文)
|
|
418
|
+
- 100% 单元测试覆盖
|
|
419
|
+
- C# v0.9.5.2 互操作性验证
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 贡献
|
|
424
|
+
|
|
425
|
+
欢迎贡献!请遵循以下步骤:
|
|
426
|
+
|
|
427
|
+
1. Fork 本仓库
|
|
428
|
+
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
429
|
+
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
430
|
+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
|
431
|
+
5. 开启 Pull Request
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
## 许可证
|
|
436
|
+
|
|
437
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## 联系方式
|
|
442
|
+
|
|
443
|
+
- 问题反馈:[GitHub Issues](https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2/issues)
|
|
444
|
+
- 代码仓库:[GitHub](https://github.com/xiaoyanghuo/LiteNetLib-Python-0.9.5.2)
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
**LiteNetLib v0.9.5.2 的 Python 实现版本**
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
litenetlib/__init__.py,sha256=CsJqyfCDDisdwcRdG-mgH9Wq2vB5UYxe-YDQ5g4r1TM,1937
|
|
2
|
+
litenetlib/channels/__init__.py,sha256=ZiNs-m_c1cA1i8olGcK9R6cd7EkQStLzwrUZEyx3X2A,424
|
|
3
|
+
litenetlib/channels/base_channel.py,sha256=9YXkUdXPDSxnJZmbPAXj9q9uZSHdMMOPH1cslfsED40,3634
|
|
4
|
+
litenetlib/channels/reliable_channel.py,sha256=_WiHeylLZ8zHaGDUPzAQe-dMRnRHJkd0s9qDyMidbCY,18248
|
|
5
|
+
litenetlib/channels/sequenced_channel.py,sha256=pvBS4UM2uhHGWoCb_h4l3scTqr5WbaZM-Eba0jB2Lfw,9408
|
|
6
|
+
litenetlib/core/__init__.py,sha256=Vq6PYckIwzOB5tFkpYXeFMIyyReBVPrww5heUMNVibs,1218
|
|
7
|
+
litenetlib/core/connection_request.py,sha256=CKmgoRDXpApUfe4y_uY-crTWGoAX2hXy9Gl9HqOYUsE,7579
|
|
8
|
+
litenetlib/core/constants.py,sha256=qN-4nziJ8ig5Ip7gtm9yrYBb7PqLpyaZ-usAazk-m1s,6422
|
|
9
|
+
litenetlib/core/events.py,sha256=9zk6U8r3DUwlEUPh3NKkGmuFticVGJakOsj3prO_WWE,11467
|
|
10
|
+
litenetlib/core/internal_packets.py,sha256=AGVOu8bfhzDTmRUWqj358gNSogO2LMQp7x5MeVcJTUQ,13434
|
|
11
|
+
litenetlib/core/manager.py,sha256=wiFcy7oiL9szPhPQ9Z6e3ErI7RIj40JiVjlf0rGh-os,12866
|
|
12
|
+
litenetlib/core/packet.py,sha256=rni4RvFkvKRX0YGqROq0bQ4jPRzPoCy5fF5vEhemHy8,16608
|
|
13
|
+
litenetlib/core/peer.py,sha256=CUtDZ4HWnEmr2w5GsJkdn8yrlfKpc0K3-mdBQt1IiZE,11175
|
|
14
|
+
litenetlib/utils/__init__.py,sha256=b8mraSPLgT2bCTdvc_fHwY-yC3iiwaXiyOX9dqjP4CA,564
|
|
15
|
+
litenetlib/utils/data_reader.py,sha256=WDFpppAHK8kQdA40zo9stZK-jxmiQNgJt15P-6OZQ0U,14743
|
|
16
|
+
litenetlib/utils/data_writer.py,sha256=zs9wIgNYkO090yK_qce30xiJ8-dgJU08ekJptpTWB8w,13198
|
|
17
|
+
litenetlib/utils/fast_bit_converter.py,sha256=E0dLE8XO2JkOpKpEZdtnN6dM_XGAxiBsLGCQSqV8Jkk,8039
|
|
18
|
+
litenetlib/utils/net_utils.py,sha256=z0zZhP0KZg41AYXQTtCyDWZaHXcg4pv-EPclurwGsBc,5381
|
|
19
|
+
litenetlib_0952-1.0.0.dist-info/licenses/LICENSE,sha256=02C0W6ib8DjINTdsxcC_BQ-iM0zgXCqTzurPBrIq90k,1089
|
|
20
|
+
litenetlib_0952-1.0.0.dist-info/METADATA,sha256=wA1ptvquvQpgBE3SeMvAWltjffyCnBjtMJe6hFxYxcU,11892
|
|
21
|
+
litenetlib_0952-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
22
|
+
litenetlib_0952-1.0.0.dist-info/top_level.txt,sha256=ttNX0gktlziGz3HtzgdChRKzVySC8qUbVm7gZtbfguY,11
|
|
23
|
+
litenetlib_0952-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xiaoyanghuo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
litenetlib
|