Python Websockets Can't Connect Over Internet
Solution 1:
Your line:
websockets.serve(handler, host='127.0.0.1', port=6969)
provides a specific address on which the websockets server listens. Your server will only listen on that address; any requests to any other address will never be seen.
From https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.create_server :
The
hostparameter can be a string, in that case the TCP server is bound tohostandport. The host parameter can also be a sequence of strings and in that case the TCP server is bound to all hosts of the sequence. Ifhostis an empty string orNone, all interfaces are assumed and a list of multiple sockets will be returned (most likely one for IPv4 and another one for IPv6).
You have bound your webserver to 127.0.0.1, which is a special address that only ever refers to the local machine. This address is also known as localhost. No other machine can ever connect to your localhost.
The solution is to provide an empty string or None (the default value). In this case, your web server will listen for requests sent to any address.
websockets.serve(handler, port=6969)
Post a Comment for "Python Websockets Can't Connect Over Internet"