PHP development with a Mac socket, but directly in the Socket--blind directly lost, ask the big God solution

Source: Internet
Author: User
Keywords Socket PHP
socketphp

The relevant code is as follows, $socket =socket_create (Af_inet,sock_stream, $commonProtocol)

or die("cannot create socket\n");  //绑定socket到端口  $result=socket_bind($socket,$host,$port) or die("cannot bind port to socket\n"); //开始监听这个端口  $result=socket_listen($socket,4) or die("could not set up socket listen\n");  //接受连接,另一个socket来处理通信  $msgsock=socket_accept($socket) or die("cannot accept incoming connection\n");  if($msgsock){      echo date("Y-m-d H:i:s D a");  }  //读取客户端发送过来的信息  $input=socket_read($msgsock,1024) or die("cannot read input\n");  $input=trim($input);  $output=strrev($input)."顺序反过来了吧\n";  //对接收到的信息进行处理,然后返回到客户端  socket_write($msgsock,$output,strlen($output)) or die("cannot write");  //关闭socket连接  socket_close($msgsock);  socket_close($socket);  

Show cannot bind port to socket directly on the webpage, please explain!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.