简体   繁体   中英

AWS EC2 client/server can't communicate via Node HTTP server

I have two AWS EC2 instanses. A Server and a client Node JS app.

Locally my code is working fine. But at AWS the client simply shuts down after some time - like 30 sec - without any warning/exception (For some reason it can't find and connect to the server)

Both AWS instances are running: Windows Server 2016 Base.

Both AWS instance have their own sererate "AWS security group". Just to make sure i'm not blocking any thing both security groups currently allow: "All traffic to ANY IP" - both Ingoing and Outgoing traffic.

Both instances run in the same "Availability zone" in AWS.

The server is listening at host: '0.0.0.0', port: 4080. And the client tries to connect to the server's IP at port 4080. I have tried to connect to all possible options - like:

  1. Public DNS (IPv4)
  2. IPv4 Public IP
  3. Elastic IP
  4. Private IPs

I can't even ping the server's IP from the client or from my own PC. I can access both AWS instances fine via RDP.

Here is a bit of my code:

SERVER.JS

var server = require('http').createServer();
var WebSocketServer = require('ws').Server;

var wss = new WebSocketServer({ server: server });

server.on('request', app);
server.listen(_port, '0.0.0.0', function () { console.log('SERVER STARTED! (listening on port # ' + _port + ')') });

CLIENT.JS

var WebSocket = require('ws');
var _ws = new WebSocket(THE_SERVER_IP);

_ws.on('open', function open() {

            ...
        });

        _ws.on('message', function (data, flags) {

            ...
        });

        _ws.on('close', function close() {
            ...
        });

解决方案:我向运行server.js应用程序的服务器中的Windows防火墙添加了一个自定义TCP规则-允许客户端的IP连接到端口4080。完成。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM