无法使用ubuntu平台在ec2机器上创建tcp服务器套接字

无法使用ubuntu平台在ec2机器上创建tcp服务器套接字

问题描述:

I am trying to create a tcp server on an ec2 machine with ubuntu platform. While php is running fine from the index.php file, the code returns false at following command:

socket_create(AF_NET,SOCK_STREAM,SQL_TCP);

Although it returns false, socket_last_error() returns 0. I checked output of phpinfo(), and the table shows sockets as enabled. I verified the security group settings from the aws console. It allows ssh and http traffic.

Please suggest what I might have missed in the configurations of the machine.

Thanks in advance.

我正在尝试使用ubuntu平台在ec2机器上创建tcp服务器。 虽然php从index.php文件运行正常,但代码在以下命令返回false: p>

  socket_create(AF_NET,SOCK_STREAM,SQL_TCP); 
  code>  
 
 

虽然它返回false,但socket_last_error()返回0.我检查了phpinfo()的输出,该表显示套接字已启用。 我从aws控制台验证了安全组设置。 它允许ssh和http流量。 p>

请建议我在机器配置中可能遗漏的内容。 p>

提前致谢。 p > div>

As per the documentation of socket_create, the correct parameters are:

socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

PS: notice typo in AF_INET and SOL_TCP

I just tried it on a fresh aws t1.micro instance and it worked. (Pls note that you might have to add rules in security group's inbound rules if you want external world to communicate on the opened tcp socket).