socketflow 0.1.0__tar.gz
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.
- socketflow-0.1.0/PKG-INFO +308 -0
- socketflow-0.1.0/README.md +261 -0
- socketflow-0.1.0/setup.cfg +4 -0
- socketflow-0.1.0/setup.py +104 -0
- socketflow-0.1.0/socketflow/__init__.py +45 -0
- socketflow-0.1.0/socketflow/client_side/__init__.py +3 -0
- socketflow-0.1.0/socketflow/client_side/client.py +383 -0
- socketflow-0.1.0/socketflow/global_side/__init__.py +13 -0
- socketflow-0.1.0/socketflow/global_side/blueprint.py +118 -0
- socketflow-0.1.0/socketflow/global_side/compression.py +155 -0
- socketflow-0.1.0/socketflow/global_side/dispatcher.py +104 -0
- socketflow-0.1.0/socketflow/global_side/event.py +69 -0
- socketflow-0.1.0/socketflow/global_side/exceptions.py +100 -0
- socketflow-0.1.0/socketflow/global_side/message_handler.py +38 -0
- socketflow-0.1.0/socketflow/global_side/message_manager.py +98 -0
- socketflow-0.1.0/socketflow/server_side/__init__.py +3 -0
- socketflow-0.1.0/socketflow/server_side/server.py +407 -0
- socketflow-0.1.0/socketflow.egg-info/PKG-INFO +308 -0
- socketflow-0.1.0/socketflow.egg-info/SOURCES.txt +20 -0
- socketflow-0.1.0/socketflow.egg-info/dependency_links.txt +1 -0
- socketflow-0.1.0/socketflow.egg-info/not-zip-safe +1 -0
- socketflow-0.1.0/socketflow.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socketflow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An asynchronous networking library for Python with advanced features
|
|
5
|
+
Home-page: https://github.com/ayammaximilian/socketflow
|
|
6
|
+
Author: SocketFlow Team
|
|
7
|
+
Author-email: contact@socketflow.dev
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/ayammaximilian/socketflow/issues
|
|
10
|
+
Project-URL: Source, https://github.com/ayammaximilian/socketflow
|
|
11
|
+
Project-URL: Documentation, https://socketflow.dev
|
|
12
|
+
Keywords: networking,tcp,socket,server,client,async,asyncio,real-time,messaging,clustering,ssl,tls,encryption,compression,middleware,events,blueprint,failover,load-balancing,redis,distributed
|
|
13
|
+
Platform: any
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Topic :: Internet
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
30
|
+
Classifier: Topic :: System :: Networking
|
|
31
|
+
Classifier: Topic :: Communications
|
|
32
|
+
Classifier: Topic :: Security :: Cryptography
|
|
33
|
+
Requires-Python: >=3.7
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
Dynamic: author
|
|
36
|
+
Dynamic: author-email
|
|
37
|
+
Dynamic: classifier
|
|
38
|
+
Dynamic: description
|
|
39
|
+
Dynamic: description-content-type
|
|
40
|
+
Dynamic: home-page
|
|
41
|
+
Dynamic: keywords
|
|
42
|
+
Dynamic: license
|
|
43
|
+
Dynamic: platform
|
|
44
|
+
Dynamic: project-url
|
|
45
|
+
Dynamic: requires-python
|
|
46
|
+
Dynamic: summary
|
|
47
|
+
|
|
48
|
+
# SocketFlow
|
|
49
|
+
|
|
50
|
+
A high-performance, dependency-free TCP networking library for Python with advanced features like compression, event handling, bidirectional keepalive, and more.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **Zero Dependencies** - Uses only Python's standard library
|
|
55
|
+
- **Bidirectional Keepalive** - Both client and server independently monitor connection health
|
|
56
|
+
- **TCP-Level Keepalive** - OS-managed keepalive for reliable connection detection
|
|
57
|
+
- **Compression** - Support for zlib, lzma, and bz2 compression
|
|
58
|
+
- **Event-Driven Architecture** - Flexible event dispatcher for handling server/client events
|
|
59
|
+
- **Blueprint System** - Organize your code with reusable blueprints
|
|
60
|
+
- **Middleware Support** - Add custom middleware to request/response processing
|
|
61
|
+
- **Path-Based Routing** - Route messages to specific handlers using paths
|
|
62
|
+
- **Efficient Buffer Handling** - O(N) buffer processing with offset pattern
|
|
63
|
+
- **Type Hints** - Full type annotations for better IDE support
|
|
64
|
+
- **Cross-Platform** - Works on Windows, Linux, and macOS
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install socketflow
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Full documentation available at:** https://socketflow.dev/
|
|
73
|
+
|
|
74
|
+
Or install from source:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/ayammaximilian/socketflow.git
|
|
78
|
+
cd socketflow
|
|
79
|
+
pip install .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
### Server Example
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from socketflow import TcpServer, EventType
|
|
88
|
+
|
|
89
|
+
# Create server
|
|
90
|
+
server = TcpServer(
|
|
91
|
+
host="127.0.0.1",
|
|
92
|
+
port=8080,
|
|
93
|
+
keepalive_interval=30.0,
|
|
94
|
+
keepalive_max_missed=3,
|
|
95
|
+
compress=True
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# Register event handler
|
|
99
|
+
@server.event(EventType.Server.MESSAGE)
|
|
100
|
+
def handle_message(data):
|
|
101
|
+
print(f"Received: {data}")
|
|
102
|
+
return "Response"
|
|
103
|
+
|
|
104
|
+
# Start server
|
|
105
|
+
server.start()
|
|
106
|
+
server.wait() # Keep server running
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Client Example
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from socketflow import TcpClient, EventType
|
|
113
|
+
|
|
114
|
+
# Create client
|
|
115
|
+
client = TcpClient(
|
|
116
|
+
host="127.0.0.1",
|
|
117
|
+
port=8080,
|
|
118
|
+
keepalive_interval=30.0,
|
|
119
|
+
keepalive_max_missed=3,
|
|
120
|
+
compress=True
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Connect to server
|
|
124
|
+
client.connect()
|
|
125
|
+
|
|
126
|
+
# Register event handler
|
|
127
|
+
@client.event(EventType.Client.MESSAGE)
|
|
128
|
+
def handle_message(data):
|
|
129
|
+
print(f"Received: {data}")
|
|
130
|
+
|
|
131
|
+
# Send message
|
|
132
|
+
response = client.send("Hello, Server!", wait_response=True)
|
|
133
|
+
print(f"Server response: {response}")
|
|
134
|
+
|
|
135
|
+
# Disconnect
|
|
136
|
+
client.disconnect()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Configuration
|
|
140
|
+
|
|
141
|
+
### Server Options
|
|
142
|
+
|
|
143
|
+
| Parameter | Type | Default | Description |
|
|
144
|
+
|-----------|------|---------|-------------|
|
|
145
|
+
| `host` | str | "127.0.0.1" | Server host address |
|
|
146
|
+
| `port` | int | 8080 | Server port |
|
|
147
|
+
| `compression_type` | str | "zlib" | Compression algorithm (zlib, lzma, bz2) |
|
|
148
|
+
| `compression_level` | int | 6 | Compression level (1-9) |
|
|
149
|
+
| `compress` | bool | True | Enable compression |
|
|
150
|
+
| `keepalive_interval` | float | 30.0 | Keepalive interval in seconds |
|
|
151
|
+
| `keepalive_max_missed` | int | 3 | Max missed keepalives before disconnect |
|
|
152
|
+
| `recv_buffer_size` | int | 65536 | Receive buffer size |
|
|
153
|
+
| `send_buffer_size` | int | 65536 | Send buffer size |
|
|
154
|
+
|
|
155
|
+
### Client Options
|
|
156
|
+
|
|
157
|
+
| Parameter | Type | Default | Description |
|
|
158
|
+
|-----------|------|---------|-------------|
|
|
159
|
+
| `host` | str | "127.0.0.1" | Server host address |
|
|
160
|
+
| `port` | int | 8080 | Server port |
|
|
161
|
+
| `compression_type` | str | "zlib" | Compression algorithm (zlib, lzma, bz2) |
|
|
162
|
+
| `compression_level` | int | 6 | Compression level (1-9) |
|
|
163
|
+
| `compress` | bool | True | Enable compression |
|
|
164
|
+
| `keepalive_interval` | float | 30.0 | Keepalive interval in seconds |
|
|
165
|
+
| `keepalive_max_missed` | int | 3 | Max missed keepalives before disconnect |
|
|
166
|
+
| `connection_timeout` | float | 10.0 | Connection timeout in seconds |
|
|
167
|
+
| `recv_buffer_size` | int | 65536 | Receive buffer size |
|
|
168
|
+
| `send_buffer_size` | int | 65536 | Send buffer size |
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
### TcpServer
|
|
173
|
+
|
|
174
|
+
#### Methods
|
|
175
|
+
|
|
176
|
+
- `start()` - Start the server
|
|
177
|
+
- `stop()` - Stop the server and disconnect all clients
|
|
178
|
+
- `wait()` - Block until server stops
|
|
179
|
+
- `start_and_wait()` - Start server and block
|
|
180
|
+
- `send_client(client_addr, data, path=None, wait_response=False)` - Send data to specific client
|
|
181
|
+
- `disconnect_client(client_addr)` - Disconnect a specific client
|
|
182
|
+
- `get_connected_clients()` - Get number of connected clients
|
|
183
|
+
- `is_connected(client_addr)` - Check if client is connected
|
|
184
|
+
- `event(event_type)` - Decorator to register event handler
|
|
185
|
+
- `path(path, middleware=None)` - Decorator to register path handler
|
|
186
|
+
- `register_blueprint(blueprint)` - Register a blueprint
|
|
187
|
+
|
|
188
|
+
### TcpClient
|
|
189
|
+
|
|
190
|
+
#### Methods
|
|
191
|
+
|
|
192
|
+
- `connect()` - Connect to server
|
|
193
|
+
- `disconnect()` - Disconnect from server
|
|
194
|
+
- `send(data, path=None, wait_response=False)` - Send data to server
|
|
195
|
+
- `wait()` - Block until client disconnects
|
|
196
|
+
- `connect_and_wait()` - Connect and block
|
|
197
|
+
- `is_connected()` - Check if connected
|
|
198
|
+
- `event(event_type)` - Decorator to register event handler
|
|
199
|
+
- `path(path, middleware=None)` - Decorator to register path handler
|
|
200
|
+
- `register_blueprint(blueprint)` - Register a blueprint
|
|
201
|
+
|
|
202
|
+
## Events
|
|
203
|
+
|
|
204
|
+
### Server Events
|
|
205
|
+
|
|
206
|
+
- `EventType.Server.START` - Server started
|
|
207
|
+
- `EventType.Server.STOP` - Server stopped
|
|
208
|
+
- `EventType.Server.CLIENT_CONNECT` - Client connected
|
|
209
|
+
- `EventType.Server.CLIENT_DISCONNECT` - Client disconnected
|
|
210
|
+
- `EventType.Server.MESSAGE` - Message received from client
|
|
211
|
+
|
|
212
|
+
### Client Events
|
|
213
|
+
|
|
214
|
+
- `EventType.Client.CONNECT` - Connected to server
|
|
215
|
+
- `EventType.Client.DISCONNECT` - Disconnected from server
|
|
216
|
+
- `EventType.Client.MESSAGE` - Message received from server
|
|
217
|
+
|
|
218
|
+
### Global Events
|
|
219
|
+
|
|
220
|
+
- `EventType.Global.ERROR` - Error occurred
|
|
221
|
+
|
|
222
|
+
## Path-Based Routing
|
|
223
|
+
|
|
224
|
+
Send messages to specific handlers using paths:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
# Server
|
|
228
|
+
@server.path("/user/login")
|
|
229
|
+
def handle_login(data):
|
|
230
|
+
# Handle login
|
|
231
|
+
pass
|
|
232
|
+
|
|
233
|
+
@server.path("/user/register")
|
|
234
|
+
def handle_register(data):
|
|
235
|
+
# Handle registration
|
|
236
|
+
pass
|
|
237
|
+
|
|
238
|
+
# Client
|
|
239
|
+
client.send(data, path="/user/login")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Blueprints
|
|
243
|
+
|
|
244
|
+
Organize your code with blueprints:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from socketflow import Blueprint
|
|
248
|
+
|
|
249
|
+
user_bp = Blueprint("user")
|
|
250
|
+
|
|
251
|
+
@user_bp.path("/login")
|
|
252
|
+
def login(data):
|
|
253
|
+
pass
|
|
254
|
+
|
|
255
|
+
@user_bp.path("/register")
|
|
256
|
+
def register(data):
|
|
257
|
+
pass
|
|
258
|
+
|
|
259
|
+
# Register blueprint
|
|
260
|
+
server.register_blueprint(user_bp)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Keepalive
|
|
264
|
+
|
|
265
|
+
SocketFlow implements bidirectional keepalive at two levels:
|
|
266
|
+
|
|
267
|
+
1. **Application-Level Keepalive** - Custom ping/pong messages
|
|
268
|
+
2. **TCP-Level Keepalive** - OS-managed keepalive probes
|
|
269
|
+
|
|
270
|
+
Both client and server independently monitor connection health based on their own configurations.
|
|
271
|
+
|
|
272
|
+
## Compression
|
|
273
|
+
|
|
274
|
+
Support for multiple compression algorithms:
|
|
275
|
+
|
|
276
|
+
- **zlib** - Fast compression, good balance
|
|
277
|
+
- **lzma** - High compression ratio, slower
|
|
278
|
+
- **bz2** - Good compression, moderate speed
|
|
279
|
+
|
|
280
|
+
## Error Handling
|
|
281
|
+
|
|
282
|
+
SocketFlow provides custom exception types:
|
|
283
|
+
|
|
284
|
+
- `NotConnected` - Connection not established
|
|
285
|
+
- `ConnectionTimeout` - Connection attempt timed out
|
|
286
|
+
- `KeepaliveTimeout` - Keepalive timeout
|
|
287
|
+
- `CompressionError` - Compression/decompression error
|
|
288
|
+
- `InvalidData` - Invalid message format
|
|
289
|
+
- `NoResponse` - No response received within timeout
|
|
290
|
+
- `MessageHandlerError` - Message handling error
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
MIT License - see LICENSE file for details
|
|
295
|
+
|
|
296
|
+
## Contributing
|
|
297
|
+
|
|
298
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
299
|
+
|
|
300
|
+
## Support
|
|
301
|
+
|
|
302
|
+
- GitHub Issues: https://github.com/ayammaximilian/socketflow/issues
|
|
303
|
+
- Documentation: https://socketflow.dev/
|
|
304
|
+
|
|
305
|
+
## Requirements
|
|
306
|
+
|
|
307
|
+
- Python 3.7+
|
|
308
|
+
- No external dependencies (uses only standard library)
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# SocketFlow
|
|
2
|
+
|
|
3
|
+
A high-performance, dependency-free TCP networking library for Python with advanced features like compression, event handling, bidirectional keepalive, and more.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Zero Dependencies** - Uses only Python's standard library
|
|
8
|
+
- **Bidirectional Keepalive** - Both client and server independently monitor connection health
|
|
9
|
+
- **TCP-Level Keepalive** - OS-managed keepalive for reliable connection detection
|
|
10
|
+
- **Compression** - Support for zlib, lzma, and bz2 compression
|
|
11
|
+
- **Event-Driven Architecture** - Flexible event dispatcher for handling server/client events
|
|
12
|
+
- **Blueprint System** - Organize your code with reusable blueprints
|
|
13
|
+
- **Middleware Support** - Add custom middleware to request/response processing
|
|
14
|
+
- **Path-Based Routing** - Route messages to specific handlers using paths
|
|
15
|
+
- **Efficient Buffer Handling** - O(N) buffer processing with offset pattern
|
|
16
|
+
- **Type Hints** - Full type annotations for better IDE support
|
|
17
|
+
- **Cross-Platform** - Works on Windows, Linux, and macOS
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install socketflow
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Full documentation available at:** https://socketflow.dev/
|
|
26
|
+
|
|
27
|
+
Or install from source:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone https://github.com/ayammaximilian/socketflow.git
|
|
31
|
+
cd socketflow
|
|
32
|
+
pip install .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Server Example
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from socketflow import TcpServer, EventType
|
|
41
|
+
|
|
42
|
+
# Create server
|
|
43
|
+
server = TcpServer(
|
|
44
|
+
host="127.0.0.1",
|
|
45
|
+
port=8080,
|
|
46
|
+
keepalive_interval=30.0,
|
|
47
|
+
keepalive_max_missed=3,
|
|
48
|
+
compress=True
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Register event handler
|
|
52
|
+
@server.event(EventType.Server.MESSAGE)
|
|
53
|
+
def handle_message(data):
|
|
54
|
+
print(f"Received: {data}")
|
|
55
|
+
return "Response"
|
|
56
|
+
|
|
57
|
+
# Start server
|
|
58
|
+
server.start()
|
|
59
|
+
server.wait() # Keep server running
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Client Example
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from socketflow import TcpClient, EventType
|
|
66
|
+
|
|
67
|
+
# Create client
|
|
68
|
+
client = TcpClient(
|
|
69
|
+
host="127.0.0.1",
|
|
70
|
+
port=8080,
|
|
71
|
+
keepalive_interval=30.0,
|
|
72
|
+
keepalive_max_missed=3,
|
|
73
|
+
compress=True
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Connect to server
|
|
77
|
+
client.connect()
|
|
78
|
+
|
|
79
|
+
# Register event handler
|
|
80
|
+
@client.event(EventType.Client.MESSAGE)
|
|
81
|
+
def handle_message(data):
|
|
82
|
+
print(f"Received: {data}")
|
|
83
|
+
|
|
84
|
+
# Send message
|
|
85
|
+
response = client.send("Hello, Server!", wait_response=True)
|
|
86
|
+
print(f"Server response: {response}")
|
|
87
|
+
|
|
88
|
+
# Disconnect
|
|
89
|
+
client.disconnect()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
### Server Options
|
|
95
|
+
|
|
96
|
+
| Parameter | Type | Default | Description |
|
|
97
|
+
|-----------|------|---------|-------------|
|
|
98
|
+
| `host` | str | "127.0.0.1" | Server host address |
|
|
99
|
+
| `port` | int | 8080 | Server port |
|
|
100
|
+
| `compression_type` | str | "zlib" | Compression algorithm (zlib, lzma, bz2) |
|
|
101
|
+
| `compression_level` | int | 6 | Compression level (1-9) |
|
|
102
|
+
| `compress` | bool | True | Enable compression |
|
|
103
|
+
| `keepalive_interval` | float | 30.0 | Keepalive interval in seconds |
|
|
104
|
+
| `keepalive_max_missed` | int | 3 | Max missed keepalives before disconnect |
|
|
105
|
+
| `recv_buffer_size` | int | 65536 | Receive buffer size |
|
|
106
|
+
| `send_buffer_size` | int | 65536 | Send buffer size |
|
|
107
|
+
|
|
108
|
+
### Client Options
|
|
109
|
+
|
|
110
|
+
| Parameter | Type | Default | Description |
|
|
111
|
+
|-----------|------|---------|-------------|
|
|
112
|
+
| `host` | str | "127.0.0.1" | Server host address |
|
|
113
|
+
| `port` | int | 8080 | Server port |
|
|
114
|
+
| `compression_type` | str | "zlib" | Compression algorithm (zlib, lzma, bz2) |
|
|
115
|
+
| `compression_level` | int | 6 | Compression level (1-9) |
|
|
116
|
+
| `compress` | bool | True | Enable compression |
|
|
117
|
+
| `keepalive_interval` | float | 30.0 | Keepalive interval in seconds |
|
|
118
|
+
| `keepalive_max_missed` | int | 3 | Max missed keepalives before disconnect |
|
|
119
|
+
| `connection_timeout` | float | 10.0 | Connection timeout in seconds |
|
|
120
|
+
| `recv_buffer_size` | int | 65536 | Receive buffer size |
|
|
121
|
+
| `send_buffer_size` | int | 65536 | Send buffer size |
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
### TcpServer
|
|
126
|
+
|
|
127
|
+
#### Methods
|
|
128
|
+
|
|
129
|
+
- `start()` - Start the server
|
|
130
|
+
- `stop()` - Stop the server and disconnect all clients
|
|
131
|
+
- `wait()` - Block until server stops
|
|
132
|
+
- `start_and_wait()` - Start server and block
|
|
133
|
+
- `send_client(client_addr, data, path=None, wait_response=False)` - Send data to specific client
|
|
134
|
+
- `disconnect_client(client_addr)` - Disconnect a specific client
|
|
135
|
+
- `get_connected_clients()` - Get number of connected clients
|
|
136
|
+
- `is_connected(client_addr)` - Check if client is connected
|
|
137
|
+
- `event(event_type)` - Decorator to register event handler
|
|
138
|
+
- `path(path, middleware=None)` - Decorator to register path handler
|
|
139
|
+
- `register_blueprint(blueprint)` - Register a blueprint
|
|
140
|
+
|
|
141
|
+
### TcpClient
|
|
142
|
+
|
|
143
|
+
#### Methods
|
|
144
|
+
|
|
145
|
+
- `connect()` - Connect to server
|
|
146
|
+
- `disconnect()` - Disconnect from server
|
|
147
|
+
- `send(data, path=None, wait_response=False)` - Send data to server
|
|
148
|
+
- `wait()` - Block until client disconnects
|
|
149
|
+
- `connect_and_wait()` - Connect and block
|
|
150
|
+
- `is_connected()` - Check if connected
|
|
151
|
+
- `event(event_type)` - Decorator to register event handler
|
|
152
|
+
- `path(path, middleware=None)` - Decorator to register path handler
|
|
153
|
+
- `register_blueprint(blueprint)` - Register a blueprint
|
|
154
|
+
|
|
155
|
+
## Events
|
|
156
|
+
|
|
157
|
+
### Server Events
|
|
158
|
+
|
|
159
|
+
- `EventType.Server.START` - Server started
|
|
160
|
+
- `EventType.Server.STOP` - Server stopped
|
|
161
|
+
- `EventType.Server.CLIENT_CONNECT` - Client connected
|
|
162
|
+
- `EventType.Server.CLIENT_DISCONNECT` - Client disconnected
|
|
163
|
+
- `EventType.Server.MESSAGE` - Message received from client
|
|
164
|
+
|
|
165
|
+
### Client Events
|
|
166
|
+
|
|
167
|
+
- `EventType.Client.CONNECT` - Connected to server
|
|
168
|
+
- `EventType.Client.DISCONNECT` - Disconnected from server
|
|
169
|
+
- `EventType.Client.MESSAGE` - Message received from server
|
|
170
|
+
|
|
171
|
+
### Global Events
|
|
172
|
+
|
|
173
|
+
- `EventType.Global.ERROR` - Error occurred
|
|
174
|
+
|
|
175
|
+
## Path-Based Routing
|
|
176
|
+
|
|
177
|
+
Send messages to specific handlers using paths:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
# Server
|
|
181
|
+
@server.path("/user/login")
|
|
182
|
+
def handle_login(data):
|
|
183
|
+
# Handle login
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
@server.path("/user/register")
|
|
187
|
+
def handle_register(data):
|
|
188
|
+
# Handle registration
|
|
189
|
+
pass
|
|
190
|
+
|
|
191
|
+
# Client
|
|
192
|
+
client.send(data, path="/user/login")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Blueprints
|
|
196
|
+
|
|
197
|
+
Organize your code with blueprints:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from socketflow import Blueprint
|
|
201
|
+
|
|
202
|
+
user_bp = Blueprint("user")
|
|
203
|
+
|
|
204
|
+
@user_bp.path("/login")
|
|
205
|
+
def login(data):
|
|
206
|
+
pass
|
|
207
|
+
|
|
208
|
+
@user_bp.path("/register")
|
|
209
|
+
def register(data):
|
|
210
|
+
pass
|
|
211
|
+
|
|
212
|
+
# Register blueprint
|
|
213
|
+
server.register_blueprint(user_bp)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Keepalive
|
|
217
|
+
|
|
218
|
+
SocketFlow implements bidirectional keepalive at two levels:
|
|
219
|
+
|
|
220
|
+
1. **Application-Level Keepalive** - Custom ping/pong messages
|
|
221
|
+
2. **TCP-Level Keepalive** - OS-managed keepalive probes
|
|
222
|
+
|
|
223
|
+
Both client and server independently monitor connection health based on their own configurations.
|
|
224
|
+
|
|
225
|
+
## Compression
|
|
226
|
+
|
|
227
|
+
Support for multiple compression algorithms:
|
|
228
|
+
|
|
229
|
+
- **zlib** - Fast compression, good balance
|
|
230
|
+
- **lzma** - High compression ratio, slower
|
|
231
|
+
- **bz2** - Good compression, moderate speed
|
|
232
|
+
|
|
233
|
+
## Error Handling
|
|
234
|
+
|
|
235
|
+
SocketFlow provides custom exception types:
|
|
236
|
+
|
|
237
|
+
- `NotConnected` - Connection not established
|
|
238
|
+
- `ConnectionTimeout` - Connection attempt timed out
|
|
239
|
+
- `KeepaliveTimeout` - Keepalive timeout
|
|
240
|
+
- `CompressionError` - Compression/decompression error
|
|
241
|
+
- `InvalidData` - Invalid message format
|
|
242
|
+
- `NoResponse` - No response received within timeout
|
|
243
|
+
- `MessageHandlerError` - Message handling error
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT License - see LICENSE file for details
|
|
248
|
+
|
|
249
|
+
## Contributing
|
|
250
|
+
|
|
251
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
252
|
+
|
|
253
|
+
## Support
|
|
254
|
+
|
|
255
|
+
- GitHub Issues: https://github.com/ayammaximilian/socketflow/issues
|
|
256
|
+
- Documentation: https://socketflow.dev/
|
|
257
|
+
|
|
258
|
+
## Requirements
|
|
259
|
+
|
|
260
|
+
- Python 3.7+
|
|
261
|
+
- No external dependencies (uses only standard library)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Setup script for SocketFlow - An asynchronous networking library for Python.
|
|
4
|
+
|
|
5
|
+
SocketFlow provides both server and client functionality with advanced features like
|
|
6
|
+
clustering, compression, middleware, event handling, SSL/TLS encryption, and more.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from setuptools import setup, find_packages
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Read the README file for long description
|
|
14
|
+
def read_readme():
|
|
15
|
+
readme_path = os.path.join(os.path.dirname(__file__), "README.md")
|
|
16
|
+
if os.path.exists(readme_path):
|
|
17
|
+
with open(readme_path, "r", encoding="utf-8") as f:
|
|
18
|
+
return f.read()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Read version from __init__.py
|
|
22
|
+
def get_version():
|
|
23
|
+
init_path = os.path.join(os.path.dirname(__file__), "socketflow", "__init__.py")
|
|
24
|
+
with open(init_path, "r", encoding="utf-8") as f:
|
|
25
|
+
for line in f:
|
|
26
|
+
if line.startswith("__version__"):
|
|
27
|
+
return line.split("=")[1].strip().strip("\"'")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
setup(
|
|
31
|
+
name="socketflow",
|
|
32
|
+
version=get_version(),
|
|
33
|
+
author="SocketFlow Team",
|
|
34
|
+
author_email="contact@socketflow.dev",
|
|
35
|
+
description="An asynchronous networking library for Python with advanced features",
|
|
36
|
+
long_description=read_readme(),
|
|
37
|
+
long_description_content_type="text/markdown",
|
|
38
|
+
url="https://github.com/ayammaximilian/socketflow",
|
|
39
|
+
project_urls={
|
|
40
|
+
"Bug Reports": "https://github.com/ayammaximilian/socketflow/issues",
|
|
41
|
+
"Source": "https://github.com/ayammaximilian/socketflow",
|
|
42
|
+
"Documentation": "https://socketflow.dev",
|
|
43
|
+
},
|
|
44
|
+
packages=find_packages(),
|
|
45
|
+
classifiers=[
|
|
46
|
+
"Development Status :: 5 - Production/Stable",
|
|
47
|
+
"Intended Audience :: Developers",
|
|
48
|
+
"License :: OSI Approved :: MIT License",
|
|
49
|
+
"Operating System :: OS Independent",
|
|
50
|
+
"Programming Language :: Python :: 3",
|
|
51
|
+
"Programming Language :: Python :: 3.7",
|
|
52
|
+
"Programming Language :: Python :: 3.8",
|
|
53
|
+
"Programming Language :: Python :: 3.9",
|
|
54
|
+
"Programming Language :: Python :: 3.10",
|
|
55
|
+
"Programming Language :: Python :: 3.11",
|
|
56
|
+
"Programming Language :: Python :: 3.12",
|
|
57
|
+
"Topic :: Internet",
|
|
58
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
59
|
+
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
|
|
60
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
61
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
62
|
+
"Topic :: System :: Networking",
|
|
63
|
+
"Topic :: Communications",
|
|
64
|
+
"Topic :: Security :: Cryptography",
|
|
65
|
+
],
|
|
66
|
+
python_requires=">=3.7",
|
|
67
|
+
install_requires=[],
|
|
68
|
+
keywords=[
|
|
69
|
+
"networking",
|
|
70
|
+
"tcp",
|
|
71
|
+
"socket",
|
|
72
|
+
"server",
|
|
73
|
+
"client",
|
|
74
|
+
"async",
|
|
75
|
+
"asyncio",
|
|
76
|
+
"real-time",
|
|
77
|
+
"messaging",
|
|
78
|
+
"clustering",
|
|
79
|
+
"ssl",
|
|
80
|
+
"tls",
|
|
81
|
+
"encryption",
|
|
82
|
+
"compression",
|
|
83
|
+
"middleware",
|
|
84
|
+
"events",
|
|
85
|
+
"blueprint",
|
|
86
|
+
"failover",
|
|
87
|
+
"load-balancing",
|
|
88
|
+
"redis",
|
|
89
|
+
"distributed",
|
|
90
|
+
],
|
|
91
|
+
entry_points={},
|
|
92
|
+
include_package_data=True,
|
|
93
|
+
package_data={
|
|
94
|
+
"socketflow": [
|
|
95
|
+
"*.md",
|
|
96
|
+
"*.txt",
|
|
97
|
+
"*.yml",
|
|
98
|
+
"*.yaml",
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
zip_safe=False,
|
|
102
|
+
platforms=["any"],
|
|
103
|
+
license="MIT",
|
|
104
|
+
)
|