Websockets connection failure on amazon ec2
Asked Answered
A

6

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.

Ashliashlie answered 6/8, 2012 at 10:33 Comment(1)
Do you have your firewalls setup so that 2880 is open?Lizettelizotte
A
13

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

Arraignment answered 18/12, 2014 at 7:33 Comment(4)
How to do do it? I am using Python + Tornado. It works well in local machine but not in EC2 Ubuntu.Stumper
Thanks @ABIRAMAN. Yes for websocket connection in your EC2 use Public IP instead of privateHittel
Will try to answer Click Here to the posted questionClotilde
This answer has saved my moronic backside twice in the passed few years.Oxidate
R
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

Rubadub answered 15/10, 2012 at 7:38 Comment(3)
johan.heapsource.com/post/31047804966/…Whitesell
All links are dead by now :(Lyophobic
The entire domain seems offline but here's a wayback link: web.archive.org/web/20160328183724/http://johan.heapsource.com/… This information is very outdated though, so I don't know how much it'll help anymore.Rubadub
H
4

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

Harveyharvie answered 21/12, 2017 at 6:43 Comment(0)
O
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?

Omalley answered 22/7, 2013 at 4:54 Comment(0)
W
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.

Wilder answered 8/4, 2023 at 14:5 Comment(0)
U
-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.

Unearth answered 21/8, 2012 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.