13

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.

user371427
  • 143
  • 1
  • 1
  • 5

6 Answers6

10

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

Amit Thawait
  • 4,862
  • 2
  • 31
  • 25
ABIRAMAN
  • 929
  • 8
  • 12
8

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

moodh
  • 2,661
  • 28
  • 42
  • 2
    http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions-in – bendytree Feb 05 '14 at 20:12
  • All links are dead by now :( – Ron Jul 17 '18 at 07:54
  • The entire domain seems offline but here's a wayback link: https://web.archive.org/web/20160328183724/http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions This information is very outdated though, so I don't know how much it'll help anymore. – moodh Jul 17 '18 at 12:48
3

@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 ;)

0

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?

Daiwei
  • 40,666
  • 3
  • 38
  • 48
0

Guy from 2023 here. @abiraman's answer helped me.

Secondly, wscat is an EXCELLENT tool to debug websocket connection.

My situation:

  • AWS Ec2 server with websocket enabled.
  • Trying to connect to it from DEV LAPTOP application - NOT WORKING (ECONNREFUSED error)
  • Tried connecting from SERVER command line itself using wscat -c ws://ADDRESS:PORT
    • Public IP address is failing
    • Private address is failing
    • localhost 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.

a20
  • 5,495
  • 2
  • 30
  • 27
-1

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.

Roger
  • 7,535
  • 5
  • 41
  • 63