富贵资源网 Design By www.hznty.com

一、server.php服务端:

<"socket创建失败原因 " . socket_strerror($sock) . "\n"; 
} 
 
if (($ret = socket_bind($sock, $address, $port)) < 0) { 
    echo "创建套接字失败原因 " . socket_strerror($ret) . "\n"; 
} 
//监听 
if (($ret = socket_listen($sock, 5)) < 0) { 
    echo "监听失败原因 " . socket_strerror($ret) . "\n"; 
} 
do { 
  //接收命令  
  if (($msgsock = @socket_accept($sock)) < 0) { 
    echo "命令接收失败原因: " . socket_strerror($msgsock) . "\n"; 
    break; 
  } 
  $msg = "\nPHP Test Server. \n" ."用quit,shutdown,sun...等命令测试.\n"; 
 
  @socket_write($msgsock, $msg, strlen($msg)); 
 
  do { 
    if (false === ($buf = @socket_read($msgsock, 2048, PHP_NORMAL_READ))) { 
        echo "socket_read() failed: reason: " . socket_strerror($ret) . "\n"; 
        break 2; 
    } 
    if (!$buf = trim($buf)) { 
        continue; 
    } 
    if ($buf == 'quit') { 
        break; 
    } 
    if ($buf == 'shutdown') { 
        socket_close($msgsock); 
        break 2; 
    } 
    if ($buf == 'sun') { 
        echo'what are you doing"Backinformation : '$buf'.\n"; 
    socket_write($msgsock, $talkback, strlen($talkback)); 
    echo "$buf\n"; 
  } while (true); 
 
  socket_close($msgsock); 
 
} while (true); 
 
socket_close($sock); 
"color: #ff0000">二、client.php客户端:

<"socket创建失败原因: " . socket_strerror($socket) . "\n"; 
} else { 
    echo "OK,HE HE.\n"; 
} 
$result = socket_connect($socket, $address, $service_port); 
if ($result < 0) { 
    echo "SOCKET连接失败原因: ($result) " . socket_strerror($result) . "\n"; 
} else { 
    echo "OK.\n"; 
} 
//发送命令 
$in = "HEAD / HTTP/1.1\r\n"; 
$in .= "Connection: Close\r\n\r\n"; 
$out = ''; 
echo "Send Command.........."; 
$in = "sun\n"; 
socket_write($socket, $in, strlen($in)); 
echo "OK.\n"; 
echo "Reading Backinformatin:\n\n"; 
while ($out = socket_read($socket, 2048)) { 
    echo $out; 
} 
echo "Close socket........"; 
socket_close($socket); 
echo "OK,He He.\n\n"; 
"//img.jbzj.com/file_images/article/201702/201724101859300.jpg" alt="" />

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com