Impossible to connect a client to a remote socket on AWS

Viewed 193

I m facing an issue with an fresh dev with socket.io

I got a socket.io server that is running on a AWS EC2 instance. It's a single instance with a public (55.55.55.55) and a private ip address ( 10.0.1.1 ) on port 10000

I start the server, and then i go to a website i created on another EC2 instance which is in another VPC ( 10.5.1.1/16 ) and another public ip address 100.100.100.100

This is the code i run on this instance, the client side of the websocket ( display a simple chat test )

<script>
        const display_panel = document.getElementById('ws');
        const number_of_lines_displayed = document.getElementById('info_lines');

        let socket = io('http://55.55.55.55:10000');

        let line_counter = 0;

        socket.on('test', (msg) => {

            if(line_counter < {{ max_lines }})
            {
                let span = document.createElement('span');
                let text = document.createTextNode(msg);
                let newline = document.createElement('br');

                span.appendChild(text);
                display_panel.insertBefore(newline, display_panel.firstChild);
                display_panel.insertBefore(span, display_panel.firstChild);

                number_of_lines_displayed.innerHTML = 'line(s): ' + line_counter++;
            }
        });
    </script>

Then , i got a connection timeout.

On the server side, i ve start the server trying all the possible solution , but i was not able to connect in all the situation

  • 10.0.1.1:10000
  • 127.0.0.1:10000
  • 0.0.0.0:10000
  • 55.55.55.55:10000

in this last case, the server give me this error

 Bugsnag:  Encountered an uncaught error, terminating…
1|test | Error: listen EADDRNOTAVAIL 55.55.55.55:10000
1|test |     at Object._errnoException (util.js:992:11)
1|test |     at _exceptionWithHostPort (util.js:1014:20)
1|test |     at Server.setupListenHandle [as _listen2] (net.js:1338:19)
1|test |     at listenInCluster (net.js:1396:12)
1|test |     at doListen (net.js:1505:7)
1|test |     at _combinedTickCallback (internal/process/next_tick.js:141:11)
1|test |     at process._tickDomainCallback (internal/process/next_tick.js:218:9)
1|test |     at Function.Module.runMain (module.js:695:11)
1|test |     at startup (bootstrap_node.js:191:16)
1|test |     at bootstrap_node.js:612:3

I don't see how i can make this thing working. As i m trying to reach public ip, i should not need a bridge between the VPC ( would be my favourite solution )

Netstat give me this in all case

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 10.0.1.1:10000          0.0.0.0:*               LISTEN      18132/test.js

Everything is working fine on local environment, so the code is not the issue, it look mainly to be a network issue.

Thanks for the help !

1 Answers

Found the issue : We needed to open the port in the AWS console on the EC2 instance.

Instance > security group > inbound rule

Related