Reputation: 143
I have a netty server running the atmosphere framework for a real-time notification system over websockets.
The system works perfectly on my local machine, but when I deploy it on EC2, It just does not seem to work. I am able to telnet to the remote Netty server though. The server is accessible and ports are open on EC2
Firefox throws the following error
Using URL: ws://beta.myapp.com:2880/myhandle?id=1&name=Chinese_food_rule_2& X-Atmosphere-tracking-id=35490c47-59d6-abf6-36fa-431aa340d90a&X-Atmosphere-Framework=0.9&X-Atmosphere-Transport=websocket&X-Cache-Date=0&Content-Type=application/json
Websocket error, reason: undefined
Firefox can't establish a connection to the server at ws://beta.myapp.com:2880/myhandle?id=1&name=Chinese_food_rule_2&X-Atmosphere-tracking-id=35490c47-59d6-abf6-36fa-431aa340d90a&X-Atmosphere-Framework=0.9&X-Atmosphere-Transport=websocket&X-Cache-Date=0&Content-Type=application/json.
Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent).
The server does not even get a request, this leads me to think that this is some EC2 web sockets gotcha which I am not aware of.
Upvotes: 13
Views: 27831
Reputation: 5641
Guy from 2023 here. @abiraman's answer helped me.
Secondly, wscat is an EXCELLENT tool to debug websocket connection.
My situation:
ECONNREFUSED
error)wscat -c ws://ADDRESS:PORT
Public IP address
is failingPrivate address
is failinglocalhost
or 127.0.0.1
is passing (on the server)After reading Abirahman's answer, I tried stopping and re-launching the websocket service on my private IP
- it worked!
Now question is - I'm pretty sure this setup (ws
on 127.0.0.1
) was working before it suddenly stopped working .. is this an AWS quirk? Is this a flaky solution that might break again? Please share any experience in comments - thanks.
Upvotes: 0
Reputation: 2711
Are you using an ELB? If yes you'll need to switch over to TPC instead of HTTP as websockets isn't supported in the HTTP layer. You will lose stickiness and the possibility to retrieve client IP when running TCP but Websockets will work all the way through. =)
More information on EC2/ELB/Websockets:
http://johan.firebase.co/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions-in
http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions-in
https://web.archive.org/web/20160328183724/http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions
Upvotes: 8
Reputation: 969
I got this same issue in php.
The solution is: create websocket using your private ip
address of EC2. and connect that websocket using your EC2 public ip address or url with web socket port
you will get response from EC2 web socket
Upvotes: 13
Reputation: 101
@ABIRAMAN got me the closest.
I had been connecting to the websocket (HapiJS/NES) with localhost like so:
const client = new Nes.Client('ws://localhost:3000')
Changing to the public AWS IP as below and it works:
const client = new Nes.Client('ws://5.5.5.5:3000')
Note that I also allowed 3000 on 127.0.0.1 and 0.0.0.0/0 in Amazon's EC2 control panel. Also, 5.5.5.5 is not the IP Amazon gave me ;)
Upvotes: 4
Reputation: 43556
WebSocket is using the same port as http.
However, Netty Server version lower than 4.0 does not support newer version of WebSocket.
http://netty.io/news/2011/11/17/websockets.html
What version are you using?
Upvotes: 0
Reputation: 7612
With nc (commandline linux / OSX) you can easy check if your ports are up and running.
nc -z www.google.com 80
If not, then check your security groups. Login on EC2:
Left under NETWORK & SECURITY: Select Security Groups -> open default -> inbound. There you can create new rules.
Upvotes: -1