Search code examples
javascriptpythonsslnetwork-programmingwebsocket

SSL Websocket can't establish a connection since today


I wish all readers Merry Christmas and nice gifts, My christmas gift was a connection error with my websocket project.

Backend is a Ubuntu Linux virtual instance with an apache server and python 3.10 with websockets as lib. Frontend is a Ubuntu Linux virtual instance with an apache server and a builded webgl appliance.

Since today i cant create a connection with the same code. JS:

const socket = new WebSocket("wss://domain:port");
..

Python:

...
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile="./cert.pem", keyfile="./privkey.pem")


async def main():
    async with websockets.serve(server, "", port, ssl=ssl_context):
        await asyncio.Future()  # run forever

asyncio.run(main())

The frontend is on a diferent webserver as the websocket server. I can create a connection with ws. The port is open (i checked it in my cloud overview and over ufw and nmap) I have ssl certs for my frontend and backend with differenz domains/ips created over lets encrypt and these are valid today.

ERROR Message: "firefox can't establish a connection to the server wss://domain:port"

Error

Have anybody an idea why this sucks up today ?

What i did: Restarted my pc Restarted my cloud pc Drank a beer Reseted my code to a date who i know 1oo% that was working Tested it without ssl

Expected result: connection can created over ssl..


Solution

  • I did a workaround but I don't know why my problem occurs today...

    Workaround: Run my Python Server(venv) on the same host from frontend.

    Javascript:

    socket = new WebSocket("ws://localhost:port");
    

    Python

    async with websockets.serve(server, "localhost", port):
    

    This solves my issue and I don't need a cert file but i have the load on one server.