简体   繁体   English

Amazon EC2服务器TCP套接字连接

[英]Amazon EC2 server TCP Socket Connection

I have developed a Java server using Eclipse that accepts TCP socket connection from android client, performs some computations, and returns the result to the android phone using this socket. 我开发了一个使用Eclipse的Java服务器,它接受来自android客户端的TCP套接字连接,执行一些计算,并使用这个套接字将结果返回给android手机。 I tried it on Wi-Fi. 我在Wi-Fi上尝试过。

I want now to move the Java server to the cloud - basically amazon EC2. 我现在想要将Java服务器移动到云端 - 基本上是亚马逊EC2。 Is this possible? 这可能吗? I am just using a simple tcp socket connection. 我只是使用一个简单的TCP连接套接字。 I have checked and couldn't find an example but came across "elastic beanstalk". 我检查过,找不到一个例子,但遇到了“弹性豆茎”。 Any help is appreciated, maybe a link or tutorial with such an example. 任何帮助表示赞赏,可能是这样一个例子的链接或教程。

can i convert my java project to .war and use it or can i install eclipse on the cloud and run it as i do locally? 我可以将我的java项目转换为.war并使用它,或者我可以在云上安装eclipse并像在本地一样运行它吗?

It is definitely possible. 这绝对是可能的。 And you don't have to convert your project to a .war, unless you want to. 除非您愿意,否则您不必将项目转换为.war。 All you have to do is: 你所要做的就是:

  • Pick the Amazon Image (AMI) you want to use - Amazon Linux is a good place to start, but there are plenty of other options, including Ubuntu and Windows. 选择你想要使用的亚马逊影像(AMI) - 亚马逊Linux是一个很好的起点,但还有很多其他的选择,包括Ubuntu和Windows。

  • Set up a security group - you need to set an incoming rule for your server's port number. 设置安全组 - 您需要为服务器的端口号设置传入规则。 It is pretty easy to do this from the Amazon web-based console. 从亚马逊基于Web的控制台很容易做到这一点。

  • Start a machine and assign it to the security group you created. 启动计算机并将其分配给您创建的安全组。 Again, this is easily accomplished from the amazon web console. 同样,这可以通过亚马逊网络控制台轻松完成。

Once the machine is up, log in (using ssh for Linux or Remote Desktop for windows) and install your server. 机器启动后,登录(使用ssh for Linux或Remote Desktop for windows)并安装服务器。

A few things to remember: 要记住的一些事项:

  • Since you are now running on a public server, sooner or later your server will be attacked. 由于您现在正在公共服务器上运行,因此服务器迟早会受到攻击。 EVERYONE gets attacked. 每个人都受到攻击。 If all you are opening is your single application port, make sure it is secured. 如果您打开的只是您的单个应用程序端口,请确保它是安全的。

  • An Amazon server has a private and public IP. 亚马逊服务器具有私有和公共IP。 Your client application will connect to the public IP. 您的客户端应用程序将连接到公共IP。

  • Servers can fail, and new servers get new public IPs! 服务器可能会失败,新服务器会获得新的公共IP! You need to prepare for this. 你需要为此做好准备。 Either make the IP in the client configurable, or look into something like Amazon Elastic IPs or dynamic DNS. 使客户端中的IP可配置,或者查看Amazon Elastic IP或动态DNS等内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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