socket_bind():无法绑定地址[99](Ubuntu的在Amazon EC2)绑定、地址、socket_bind、Amazon

由网友(薄情大哥)分享简介:我试图使用套接字在一个EC2实例,但是当我尝试运行code,我得到了以下错误:PHP的警告:socket_bind():无法绑定地址[99]:不能在sockets_test.php在线45分配请求的地址下面是相关code部分:$ CFG =新stdClass的();$ CFG-> chat_serverip =...

我试图使用套接字在一个EC2实例,但是当我尝试运行code,我得到了以下错误:

  

PHP的警告:socket_bind():无法绑定地址[99]:不能   在sockets_test.php在线45分配请求的地址

下面是相关code部分:

  $ CFG =新stdClass的();
$ CFG-> chat_serverip ='MY_PUBLIC_EC2_IP';
$ CFG-> chat_serverport ='9111';

$ listen_socket = socket_create(AF_INET,SOCK_STREAM,0))
socket_bind($ listen_socket,$ CFG-> chat_serverip,$ CFG-> chat_serverport)
 

如果我用127.0.0.1或私有IP这工作得很好。 我安集团拥有的规则:

  0〜65535 0.0.0.0/0(TCP)
0-65535 0.0.0.0/0(UDP)
所有0.0.0.0/0(ICMP)
 
在C 中如何判断socket的状态,如是否连接,是否阻塞,bind到哪里等 有相关的资料也可以,高分悬赏

解决方案

您不能绑定到外部IP,你必须绑定到内部IP,并设置一个规则,以允许该端口,所以当他们连接到外部IP和端口,它就会被重定向到内部IP。

I'm trying to use Sockets on an EC2 Instance, but when I try to run the code I get the following error:

PHP Warning: socket_bind(): unable to bind address [99]: Cannot assign requested address in sockets_test.php on line 45

Here is part of the relevant code:

$CFG = new stdClass();
$CFG->chat_serverip = 'MY_PUBLIC_EC2_IP';
$CFG->chat_serverport = '9111';

$listen_socket = socket_create(AF_INET, SOCK_STREAM, 0))
socket_bind($listen_socket, $CFG->chat_serverip, $CFG->chat_serverport)

This works just fine if I use 127.0.0.1 or the Private IP. My Security Group has the the rules:

0-65535 0.0.0.0/0 (TCP)
0-65535 0.0.0.0/0 (UDP)
ALL 0.0.0.0/0 (ICMP)

解决方案

You cannot bind to the external IP, you have to bind to the internal IP, and setup a rule to allow that port so when they connect to the external IP and port, it gets redirected to the internal IP.

阅读全文

相关推荐

最新文章