Posts

Showing posts from February, 2024

Creating a Minimal WebSocket Connection in Python, Inspired by the Simplicity of Socket.IO

 Simple Websocket  Connection. LIke socket io. main.py import asyncio import websockets import uuid connections = [] # when new socket connection comes this' function will executeed async def handle_websocket ( websocket , path ): #<-- path of socket recived     # creating uniq id     connection_id = str ( uuid . uuid4 ())       # This function will be append new connection     connections. append ( connection_id )             print (" Connected:- ", connection_id )     # < -- when user connected send him a message -- >     await websocket. send ( f "Your Id: { connection_id } " )         # < -- it\'s a user connection i'ts run antil user connected when user diconnected it will be ditoryed -- >     try :         while True :             try :           ...