Why can't my app talk to a websocket on an azure app service?

Viewed 184

I'm new to websockets and need to put together a very simple echo server which I decided to deploy in Azure App Service in a Docker container. Because it is so basic I decided to us the websockets package alone instead of Flask or Django.

import asyncio
import websockets

connected = set()

PORT = 4000
HOST = "0.0.0.0"

async def server(websocket, path):
    connected.add(websocket)
    print("connection!")
    try:
        async for message in websocket:
            for conn in connected:
                print(message)
                await conn.send(message)
    finally:
        connected.remove(websocket)


start_server = websockets.serve(server, HOST, PORT)

asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

Anyway, I've deployed this along with a static site in a Nginx container which is sending the requests using "wss:\"+hostname.location:4000+"\ws", the port being the one that was set on the Websockets container.

The problem is that the front-end isn't connecting to the backend. Note that I've had this working both in Docker desktop as well as a local Docker swarm I have in my lab.

I've seen it could be something to do with SSL or the fact I'm using the Basic app tier, but I just can't work it out.

Any assistance would be greatly appreciated.

Ed

<---UPDATE--->

I found in the logs that Azure is deploying the back-end server with:

- docker run -d -p 0:4000

The docker-compose file has the host port mapped to 4000. I'm not sure how I would change that?

0 Answers
Related