So I'm trying to configure a websocket server in python and cant quite figure out the issue since I came across a bunch of contradictory posts (Shall provide them later). Here is the code for the server: (I shall be using --.--.---.--- for the IP)
import asyncio
import websockets
HOST = --.--.---.---
async def echo(websocket, path):
async for message in websocket:
print(message)
asyncio.get_event_loop().run_until_complete(
websockets.serve(echo, host=HOST, port=5500))
asyncio.get_event_loop().run_forever()
This chunk of code as suggested by this post: https://bytesofgigabytes.com/python/websockets-python/ said I must put in my IP address as a host. Now I understand that this might be my modem's IP address, but in this case I spun up an AWS instance to work things out. In this case Im getting the error:
OSError: [Errno 10049] error while attempting to bind on address ('--.--.---.---', 5500): the requested address is not valid in its context
I thought it was admin priverlages, ran it from an elevated command prompt, made a rule in the firewall but to no avail.
I then came across this post: Python Websockets can't connect over internet which says that I shouldnt put in the IP address. So I didnt do that - this time the code runs but I cant connect over a websocket client which I have on html/js. The code for them is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="controller.js"></script>
</body>
</html>
and
const socket = new WebSocket('ws://--.--.---.---:5500/');
socket.addEventListener('open', function (event) {
console.log("this is running");
socket.send('Hello Server!');
});
In this case the client (in chrome) says:
controller.js:1 WebSocket connection to 'ws://--.--.---.---:5500/' failed:
EDIT 1: Tried this solution and didn't get it to work Python, socket.error: [Errno 10049]
EDIT 2: confirmed that there is some issue client side - the port is listening on netstat 
