A Network Protocol Framework
Project description
Netcore
English | 简体中文
Netcore is a lightweight communication framework that enables concurrent message transmission over a single connection. By implementing a message chunking and scheduling mechanism similar to CPU time-slicing, it allows multiple messages to be sent and received simultaneously without establishing multiple connections.
Core Features
-
Concurrent Message Transmission
- Single connection handles multiple concurrent messages
- Automatic message chunking and reassembly
- Message scheduling and prioritization
- Non-blocking message transmission
-
Smart Message Management
- Unique message ID tracking
- Automatic message queuing
- Message priority handling
- Message completion verification
-
Protocol Layer
- Binary protocol with message chunking
- Support for JSON and raw data formats
- Configurable chunk sizes
- Memory and file-based storage options
-
Transport Layer Abstraction
- Universal transport interface
- Asynchronous data transmission
- Thread safety mechanisms
- Custom transport support
Advanced Features
-
Blueprint System
- Route grouping and prefixing
- Modular application structure
- Middleware support at blueprint level
- Isolated error handling per blueprint
-
Event System
- Event subscription and publishing
- One-time event handlers
- System event monitoring
- Asynchronous event processing
-
Task Scheduler
- Delayed task execution
- Periodic task scheduling
- Priority-based scheduling
- Thread-safe task management
-
Cache System
- In-memory caching
- TTL (Time-To-Live) support
- Automatic cache cleanup
- Thread-safe operations
Quick Start
Server Example
from netcore import Endpoint, Pipe, Response, request
import socket
# Create TCP server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 8080))
server.listen(5)
conn, addr = server.accept()
# Create pipe and endpoint
pipe = Pipe(conn.recv, conn.send)
endpoint = Endpoint(pipe)
# Register handlers for concurrent messages
@endpoint.request('message1')
def handle_message1():
# This handler can run while other messages are being processed
return Response('message1', {"status": "processed"})
@endpoint.request('message2')
def handle_message2():
# Another concurrent handler
return Response('message2', {"status": "processed"})
# Start service
endpoint.start()
Client Example
from netcore import Endpoint, Pipe, Response, request
import socket
# Connect to server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 8080))
# Create pipe and endpoint
pipe = Pipe(client.recv, client.send)
endpoint = Endpoint(pipe)
# Start client (non-blocking)
endpoint.start(block=False)
# Send multiple messages concurrently
endpoint.send('message1', {"data": "First message"})
endpoint.send('message2', {"data": "Second message"})
# Both messages will be processed concurrently
Advanced Usage Examples
Blueprint Example
from netcore import Endpoint, Blueprint, Response, request
# Create a blueprint for user-related routes
user_bp = Blueprint("users", "/user")
@user_bp.request("/list")
def user_list():
return Response("/user/list", {"users": ["user1", "user2"]})
# Register blueprint to endpoint
endpoint.register_blueprint(user_bp)
Event System Example
# Subscribe to events
@endpoint.event.on('start')
def on_start():
print("Service started")
# One-time event
@endpoint.event.once('initialize')
def on_init():
print("First-time initialization")
# Emit events
endpoint.event.emit('custom_event', data={"type": "notification"})
Task Scheduler Example
# Schedule periodic task
def periodic_check():
print("Performing periodic check")
endpoint.scheduler.schedule(periodic_check, delay=5, interval=60) # Run every 60s after 5s delay
Cache System Example
# Cache expensive operations
@endpoint.request('/data')
def get_data():
# Try to get from cache
data = endpoint.cache.get("expensive_data")
if data is None:
# Compute and cache for 5 minutes
data = compute_expensive_data()
endpoint.cache.set("expensive_data", data, ttl=300)
return Response("/data", data)
How It Works
- Message Chunking: Large messages are automatically split into smaller chunks
- Concurrent Processing: Each message is processed independently
- Scheduling: Chunks from different messages are interleaved for efficient transmission
- Reassembly: Message chunks are automatically reassembled at the destination
Documentation
For detailed documentation, visit https://netcore.acdp.top
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file netcore-0.1.1.tar.gz.
File metadata
- Download URL: netcore-0.1.1.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c77b1b32ed6243260bf978052131d2e79907acb29116c6b5f18979ca54c52844
|
|
| MD5 |
af9a305fff030e3b4568d25a4112bdba
|
|
| BLAKE2b-256 |
4507bd54237febf0009f9d710bbea64400e0c777731dc21d2ba628300b26b116
|
File details
Details for the file netcore-0.1.1-py3-none-any.whl.
File metadata
- Download URL: netcore-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
859a360e0c9245ef30f45d7181427e72994684b0341e2f884090e0e4ee10fd81
|
|
| MD5 |
08aa21b9be1ea39ba3edd6421a429f38
|
|
| BLAKE2b-256 |
0566811f2ae3c1982cb1ad2d3445df8e03da5ea9593413e9d79332a8c6a35fcb
|