'Unable to establish connection with the websocket server running in cloud
We are trying to deploy our web application & uvicorn websocket server as a docker container in cloud. Web application is running on 8000 port and websocket server is running on 7001. This is in private network and can only be accessed via vpn.
We could access the web application from the browser but we could not connect to the websocket server. Firefox is giving an error Firefox failed to establish a connection to the server at ws://9x.xxx.x.xx9:7001/ws/ and chorme gives WebSocket connection to 'ws://9x.xxx.x.xx9:7001/ws/' failed.
It's working fine in my local desktop. the command we use to start the server is uvicorn --app-dir myapp mss:app --host 0.0.0.0 --port 7001,. Any suggestions as to why it is failing to work in Cloud environment?
Below is the code I have written to start the websocket server.
app = FastAPI()
app.add_middleware(CORSMiddleware,allow_origins=["ws://127.0.0.1:8000", "ws://127.0.0.1:8000", "*"])
@app.websocket("/ws/")
async def websocket_endpoint(websocket: WebSocket):
print(f"client with connection receSived at websocket server")
await manager.connect(websocket)
try:
while True:
data = await websocket.receive_text()
except WebSocketDisconnect as e:
print(e)
pass
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
