I have been struggling all evening with deploying my first website on AWS and am failing at the very last hurdle. My server side code starts:
HttpServer server = await HttpServer.bind("126.96.36.199", 4040);
WebSocket websocket = new WebSocket("ws://188.8.131.52:4040/ws");
error on initial connection SocketException: Failed to create server socket (OS Error: Cannot assign requested address, errno = 99), address = 184.108.40.206, port = 4040
You should probably use:
HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 4040);
This will bind to any IP, so you don't have to worry about figuring out what your IP address is on every EC2 server.
It's not possible to bind to the public IP address. If you wanted to bind to a specific IP address you'd have to use the private IP address.