title: WebSocket connection failed: WebSocket opening handshake was canceled
body: <p>I have recently setup an EC2 instance (in a VPC with no load balancer) and admittedly the configuration is a bit odd, but it is what is required for the web application we're running.</p>
  <p>The web server (in Haskell) is running on port 4433 (standard ports are reserved for an Apache instance) and is receiving UDP packets being broadcast from another system. I have many of the ports wide-open (just during testing) as shown here (from Security Groups):</p>
  <pre><code>Custom TCP Rule    4433     tcp 0.0.0.0/0   ✔
  Custom TCP Rule    8080     tcp 0.0.0.0/0   ✔
  SSH                22       tcp 0.0.0.0/0   ✔
  HTTP               80       tcp 0.0.0.0/0   ✔
  HTTPS              443      tcp 0.0.0.0/0   ✔
  Custom UDP Rule    30090    udp 0.0.0.0/0   ✔
  Custom UDP Rule    30089    udp 0.0.0.0/0   ✔
  </code></pre>
  <p>The JavaScript for the TCP socket makes a request to setup the socket on this same port (using the URL assigned to the AWS's public IP) and this is where the request returns the error:</p>
  <blockquote>
  <p>WebSocket connection to 'wss://[URL]:4433/projects/socket' failed: WebSocket opening handshake was canceled.</p>
  </blockquote>
  <p>Binding the socket to 0.0.0.0 results in the same error.</p>
  <p>In order to start the Haskell web server I had to reference the <em>internal</em> IP provided by AWS as it would not run when referencing the <em>public</em> IP provided by the elastic IP service. Thinking this is where the problem came in I changed my socket request to this...</p>
  <pre><code>wss://[internal ip]:4433/projects/socket
  </code></pre>
  <p>This changes the error:</p>
  <blockquote>
  <p>WebSocket connection to 'wss://[internal IP]:4433/projects/socket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED</p>
  </blockquote>
  <p>That error makes sense to me as the internal IP is not available to the outside world.</p>
  <p>Everything that I've read on websockets on AWS involves an ELB (Elastic Load Balancer) and I am not in need of one of those. I have tried all of the things in all of the currently posted answers (some of the questions haven't even gotten answers) on SO to no avail. I also setup a support case with Amazon (nearly 24 hours ago) which hasn't received a response.</p>
  <h2>Additional Info</h2>
  <p>Navigating to <code>http://[URL]:4433/projects/socket</code> yields 'WebSocket Available' where the URL is the one we wish to use as well as the Public DNS provided by AWS.</p>
  <p>Running <code>netstat -plunt</code> reveals the following:</p>
  <pre><code>tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
  tcp        0      0 [internal IP]:8080      0.0.0.0:*               LISTEN      -
  tcp        0      0 [internal IP]:4433      0.0.0.0:*               LISTEN      -
  tcp6       0      0 :::22                   :::*                    LISTEN      -
  tcp6       0      0 :::443                  :::*                    LISTEN      -
  tcp6       0      0 :::80                   :::*                    LISTEN      -
  udp        0      0 [internal IP]:30089     0.0.0.0:*                           -
  udp        0      0 0.0.0.0:30090           0.0.0.0:*                           -
  udp        0      0 0.0.0.0:11950           0.0.0.0:*                           -
  udp        0      0 0.0.0.0:68              0.0.0.0:*                           -
  udp6       0      0 :::38450                :::*                                -
  </code></pre>
  <p>Has anyone had a similar problem with websockets on AWS? If so, how did you solve the problem?</p>