Veltix v1.5.0 is out! This release brings two major features: decorator-based message routing and automatic reconnection.
Message Routing
Instead of a single global on_recv callback, you can now handle each message type with a dedicated handler:
CHAT = MessageType(code=200, name="chat")
STATUS = MessageType(code=201, name="status")
@server.route(CHAT)
def on_chat(response, client):
print(f"[{client.addr[0]}] {response.content.decode()}")
@server.route(STATUS)
def on_status(response, client):
print(f"Status: {response.content.decode()}")
Same thing on the client side:
@client.route(CHAT)
def on_chat(response, client=None):
print(f"Server: {response.content.decode()}")
Routes take priority over on_recv and run in the thread pool — slow handlers never block message reception.
Auto-Reconnect
Set retry in ClientConfig and Veltix handles the rest:
client = Client(ClientConfig(
server_addr="127.0.0.1",
port=8080,
retry=5,
retry_delay=1.0,
))
def on_disconnect(state: DisconnectState):
if state.permanent:
print(f"Disconnected — {state.reason.name}")
else:
print(f"Retrying... {state.attempt}/{state.retry_max}")
client.set_callback(Events.ON_DISCONNECT, on_disconnect)
You can also cancel or force retries at any time:
client.stop_retry() # cancel pending retries
client.retry(max=10) # force a new attempt
Other improvements
-
PerformanceMode—LOW/BALANCED/HIGHpresets to tune socket timeout and CPU usage -
BufferSize—SMALL/MEDIUM/LARGE/HUGEpresets for common buffer sizes
Breaking change
on_disconnect on the client now receives a DisconnectState argument:
# Before
client.set_callback(Events.ON_DISCONNECT, lambda: ...)
# After
client.set_callback(Events.ON_DISCONNECT, lambda state: ...)
📦 pip install veltix
📖 Documentation
⭐ GitHub
Top comments (0)