dpallot / simple-websocket-server

A python based websocket server that is simple and easy to use.
950 stars 320 forks source link

cannot successfully connect unless hostname is blank? #77

Closed patrick99e99 closed 5 years ago

patrick99e99 commented 6 years ago

I am super confused about why this is happening.

If I launch the SimpleSSLWebSocketServer server with the host name configured to my domain api.example.com then when the client tries to open a websocket connection it gets:

Error during WebSocket handshake: Unexpected response code: 502

However, if I launch the SimpleSSLWebSocketServer with an empty string instead of the domain, then it connects just fine! I tried localhost, the ip of the box, etc, everything results in a 502 except a blank string!

I don't know if this is normal? or if it's due to how my amazon webservices are setup? I have an aws application load balancer that has https port 9999 open, and forwards directly to the ec2-instance that is running the websocket server. api.example.com is being aliased to the load balancer's dns record.... But, if I run a https webserver on port 9999 instead of websockets, I can connect to it just fine-- though when I think about it, when I run a https webserver, there is nothing specifying a domain name.. it's just on localhost...

I'm super confused and don't understand why a blank string works and how I can make it work with the domain name... Any thoughts?

patrick99e99 commented 6 years ago

I was able to solve my problem by setting the host to '0.0.0.0'... It still makes absolutely no sense to me why I can't use my actual domain name, but at least I am now unblocked and can move on from this problem. It was not an option to use a blank string as I am using another library that uses SimpleSSLWebSocketServer as a dependency and it had a requirement that the hostname be some "truthy" value.

uzlonewolf commented 6 years ago

Python's socket.bind() doesn't support hostnames. See #79 for a fix.

dpallot commented 5 years ago

Merged