(202501001) New Socket.IO system started with provision for namespaces and more.

This commit is contained in:
2025-10-01 17:00:09 +05:30
parent c21ec7ba42
commit acb709667b
4 changed files with 219 additions and 27 deletions
+22 -3
View File
@@ -49,6 +49,7 @@ import socketio
# To maintain the app's state:
from wsio_v2.app_state import AppState
from wsio_v2.test.echo import EchoNamespace
from wsio_v2.finstitutions.trading.tick_out import TicksNamespace
# Debugging:
from icecream import IceCreamDebugger
@@ -83,8 +84,24 @@ app_state.http_client = httpx.AsyncClient(
)
# General:
app_state.SCRIPT_ID = None
app_state.debug = True
app_state.SERVER_HOSTNAME = str(socket.gethostname())
app_state.ALLOWED_ORIGINS = []
app_state.connected_clients = {}
# Namespaces:
app_state.NAMESPACE_DEFAULT = None
app_state.NAMESPACE_ECHO = "/echo"
app_state.NAMESPACE_TICKS = "/ticks"
app_state.NAMESPACE_ORDER_UPDATES = "/order-updates"
# Events:
app_state.EVENT_CONNECT = "connect"
app_state.EVENT_DISCONNECT = "disconnect"
app_state.EVENT_ECHO = "echo"
app_state.EVENT_TICKS = "ticks"
app_state.EVENT_ORDER_UPDATE = "order_update"
# *****************************************************************************************************************
@@ -102,7 +119,8 @@ sio = socketio.AsyncServer(
app = socketio.ASGIApp(sio)
# Register the namespaces:
sio.register_namespace(EchoNamespace(namespace = "/test", app_state = app_state))
sio.register_namespace(EchoNamespace(namespace = app_state.NAMESPACE_ECHO, app_state = app_state))
sio.register_namespace(TicksNamespace(namespace = app_state.NAMESPACE_TICKS, app_state = app_state))
# *****************************************************************************************************************
@@ -172,8 +190,9 @@ if __name__ == "__main__":
# Startup message:
app_state.printer.enable()
app_state.printer(str(args.debug))
if str(args.debug).lower().find("false") >= 0: app_state.printer.disable()
if args.debug != "True":
app_state.printer("Disabling debug print.")
app_state.printer.disable()
# Run the gateway:
freeze_support()