tests
This commit is contained in:
37
socktest.py
Normal file
37
socktest.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
import socketio
|
||||
|
||||
app = FastAPI()
|
||||
sio = socketio.AsyncServer(cors_allowed_origins="*", async_mode="asgi")
|
||||
socket_app = socketio.ASGIApp(sio, app)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def main():
|
||||
return {"message": "Hello World"}
|
||||
|
||||
|
||||
@sio.on("connect")
|
||||
async def connect(sid, env):
|
||||
print("New Client Connected to This id :" + " " + str(sid))
|
||||
await sio.emit("message", f"Hello Client, Welcome to Socket.IO Server {sid}")
|
||||
|
||||
|
||||
@sio.event
|
||||
async def message(sid, data):
|
||||
print("Message from Client: " + str(data))
|
||||
return True
|
||||
|
||||
@sio.on("disconnect")
|
||||
async def disconnect(sid):
|
||||
print("Client Disconnected: " + " " + str(sid))
|
||||
|
||||
@sio.on('*')
|
||||
async def any_event(event, sid, data):
|
||||
print("Unregisered event received, event: " + str(event) + " sid: " + str(sid) + " data: " + str(data))
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(
|
||||
"socktest:socket_app", host="0.0.0.0", port=8000, lifespan="on", reload=True
|
||||
)
|
||||
Reference in New Issue
Block a user