久久久久无码精品,四川省少妇一级毛片,老老熟妇xxxxhd,人妻无码少妇一区二区

PHP socket的配置

時間:2024-08-04 04:57:58 PHP 我要投稿
  • 相關(guān)推薦

PHP socket的配置

  PHP獨特的語法混合了C、Java、Perl以及PHP自創(chuàng)的語法。它可以比CGI或者Perl更快速地執(zhí)行動態(tài)網(wǎng)頁。以下是小編為大家搜索整理的PHP socket的配置及實例

  //phpinfo();

  //確保在連接客戶端時不會超時

  set_time_limit(0);

  $ip = 127.0.0.1;

  $port = 1935;

  /*

  +-------------------------------

  * @socket通信整個過程

  +-------------------------------

  * @socket_create

  * @socket_bind

  * @socket_listen

  * @socket_accept

  * @socket_read

  * @socket_write

  * @socket_close

  +--------------------------------

  */

  /*---------------- 以下操作都是手冊上的 -------------------*/

  if(($sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) < 0) {

  echo "socket_create() 失敗的原因是:".socket_strerror($sock)." ";

  }

  if(($ret = socket_bind($sock,$ip,$port)) < 0) {

  echo "socket_bind() 失敗的原因是:".socket_strerror($ret)." ";

  }

  if(($ret = socket_listen($sock,4)) < 0) {

  echo "socket_listen() 失敗的原因是:".socket_strerror($ret)." ";

  }

  $count = 0;

  do {

  if (($msgsock = socket_accept($sock)) < 0) {

  echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . " ";

  break;

  } else {

  //發(fā)到客戶端

  $msg ="測試成功! ";

  socket_write($msgsock, $msg, strlen($msg));

  echo "測試成功了啊 ";

  $buf = socket_read($msgsock,8192);

  $talkback = "收到的信息:$buf ";

  echo $talkback;

  if(++$count >= 5){

  break;

  };

  }

  //echo $buf;

  socket_close($msgsock);

  } while (true);

  socket_close($sock);

  ?>

  client.php

  [php] view plaincopy

  error_reporting(E_ALL);

  set_time_limit(0);

  echo "

  TCP/IP Connection

  ";

  $port = 1935;

  $ip = "127.0.0.1";

  /*

  +-------------------------------

  * @socket連接整個過程

  +-------------------------------

  * @socket_create

  * @socket_connect

  * @socket_write

  * @socket_read

  * @socket_close

  +--------------------------------

  */

  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

  if ($socket < 0) {

  echo "socket_create() failed: reason: " . socket_strerror($socket) . " ";

  }else {

  echo "OK. ";

  }

  echo "試圖連接 $ip 端口 $port... ";

  $result = socket_connect($socket, $ip, $port);

  if ($result < 0) {

  echo "socket_connect() failed. Reason: ($result) " . socket_strerror($result) . " ";

  }else {

  echo "連接OK ";

  &nbs

【PHP socket的配置】相關(guān)文章:

配置 PHP 調(diào)試環(huán)境07-20

php解析ini配置文件07-13

了解PHP環(huán)境搭建與配置的方法08-03

剛接觸eclipse php wamp時該如何配置08-24

如何配置PHP使之能同時支持GIF,PNG和JPEG09-17

關(guān)于php面試寶典及PHP面試技巧08-16

linux配置dns服務(wù)器配置命令09-22

電腦配置知識10-12

PHP的壓縮函數(shù)06-21

php高級教程01-23