DEV Community

Nytrox
Nytrox

Posted on

Veltix v1.5.0 — Routing & Auto-Reconnect

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()}")
Enter fullscreen mode Exit fullscreen mode

Same thing on the client side:

@client.route(CHAT)
def on_chat(response, client=None):
    print(f"Server: {response.content.decode()}")
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

You can also cancel or force retries at any time:

client.stop_retry()   # cancel pending retries
client.retry(max=10)  # force a new attempt
Enter fullscreen mode Exit fullscreen mode

Other improvements

  • PerformanceModeLOW / BALANCED / HIGH presets to tune socket timeout and CPU usage
  • BufferSizeSMALL / MEDIUM / LARGE / HUGE presets 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: ...)
Enter fullscreen mode Exit fullscreen mode

📦 pip install veltix
📖 Documentation
GitHub

Top comments (0)