Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, WebSocket
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
@@ -6,10 +6,14 @@ app = FastAPI()
|
|
| 6 |
async def get():
|
| 7 |
return {}
|
| 8 |
|
| 9 |
-
|
| 10 |
@app.websocket("/ws")
|
| 11 |
async def websocket_endpoint(websocket: WebSocket):
|
| 12 |
await websocket.accept()
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
| 6 |
async def get():
|
| 7 |
return {}
|
| 8 |
|
|
|
|
| 9 |
@app.websocket("/ws")
|
| 10 |
async def websocket_endpoint(websocket: WebSocket):
|
| 11 |
await websocket.accept()
|
| 12 |
+
try:
|
| 13 |
+
while True:
|
| 14 |
+
data = await websocket.receive_text()
|
| 15 |
+
print(f"Recv Message: {data}")
|
| 16 |
+
except WebSocketDisconnect:
|
| 17 |
+
print("Client disconnected")
|
| 18 |
+
except Exception as e:
|
| 19 |
+
print(f"Error: {e}")
|