小编Eri*_*rik的帖子

设置简单的服务器/客户端套接字以在AWS EC2上进行通信

我希望设置一个简单的通信套接字,通过命令行将消息从本地机器(Windows)发送到我的AWS EC2实例.我已经安装了EC2设置和节点.我的斗争是确定用于此通信的端口/主机.请参阅以下内容:

server.js(在AWS EC2上运行):

var net = require('net');

var HOST = '127.0.0.1'; 
var PORT = 8080;

// Create a server instance, and chain the listen function to it
// The function passed to net.createServer() becomes the event handler for the 'connection' event
// The sock object the callback function receives UNIQUE for each connection
net.createServer(function(sock) {

    // We have a connection - a socket object is assigned to the connection automatically
    console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);

    // Add a …
Run Code Online (Sandbox Code Playgroud)

sockets amazon-ec2 amazon-web-services node.js

3
推荐指数
1
解决办法
3609
查看次数