amazon-web-services - Dart:我应该在 aws 上通过 HttpServer.bind() 使用什么 IP 地址?

标签 amazon-web-services amazon-ec2 dart

我整个晚上都在努力在 AWS 上部署我的第一个网站,但在最后一个障碍上失败了。我的服务器端代码开始:

HttpServer server = await HttpServer.bind("51.45.28.101", 4040);

我的客户开始:

 WebSocket websocket = new WebSocket("ws://51.45.28.101:4040/ws");

51.45.28.101 是分配给我的 AWS 服务器的公共(public) IP。我正在使用 Linux EC2 服务器。我使用以下命令启动服务器:

dart main.dart

这会产生错误:

error on initial connection SocketException: Failed to create server socket (OS Error: Cannot assign requested address, errno = 99), address = 51.45.28.101, port = 4040

我在 stackoverflow 上读到过类似的问题,建议用户将 IP 设置为“0.0.0.0”。当我这样做时,我没有收到此错误。但是,我无法将客户端连接到服务器。请注意,我已正确设置安全组,并在服务器上安装了 apache,并且能够使用提供的 IP 或 DNS 地址加载基本 HTML 文件。我仅在尝试运行 main.dart 服务器代码时遇到问题。

有人可以建议我是否应该将我的服务器绑定(bind)到公共(public) IP?

非常感谢

最佳答案

你可能应该使用:

HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 4040);

这将绑定(bind)到任何 IP,因此您不必担心找出每个 EC2 服务器上的 IP 地址。

无法绑定(bind)到公共(public) IP 地址。如果您想绑定(bind)到特定 IP 地址,则必须使用私有(private) IP 地址。

关于amazon-web-services - Dart:我应该在 aws 上通过 HttpServer.bind() 使用什么 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38860972/

相关文章:

amazon-web-services - 等于 aws cloudFormation YAML 中的条件给出错误

amazon-web-services - SSH 登录 AWS EC2 错误 : packet_write_wait: Connection to x. x.x.x 端口 22:管道损坏

amazon-web-services - 无法创建 AWS Cognito 身份池

firebase - PlatformException(error, Given String is empty or null, null) 错误 flutter

amazon-web-services - 列出在 Terraform 中使用的 AWS 账单筛选器选项或名称

amazon-web-services - AWS 云观察 : how to fetch custom metrics from AWS Elastic Beanstalk

amazon-ec2 - HAProxy - 基于 URL/路径路由到后端 IP?

amazon-web-services - 如何停止 Amazon EC2 计费?

flutter - Flutter 可以扩展颜色吗?

dart - Flutter FutureBuilder 显示空白屏幕