最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)Socket服務(wù)器的代碼

 更新時(shí)間:2008年04月03日 19:08:47   作者:  
PHP實(shí)現(xiàn)Socket服務(wù)器的代碼
<?php
ob_implicit_flush();
set_time_limit(0);

$address = "192.40.7.93";//換成你自己的地址
$port = 10000;

if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
 echo "錯(cuò)誤(socket_create):".socket_strerror(socket_last_error())."<br />";

if(socket_bind($socket,$address,$port) == false)
 echo "錯(cuò)誤(socket_bind):".socket_strerror(socket_last_error())."<br />";

if(socket_listen($socket) == false)
 echo "錯(cuò)誤(socket_listen):".socket_strerror(socket_last_error())."<br />";

/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(), 
it may be told to listen for incoming connections on socket. 
*/

while(true){
 if(($msgSocket = socket_accept($socket)) == false){
  echo "錯(cuò)誤(socket_accept):".socket_strerror(socket_last_error())."<br />";
  break;
 }

 /*
 this function will accept incoming connections on that socket. 
 Once a successful connection is made, a new socket resource is returned, which may be used for communication. 
 If there are multiple connections queued on the socket, the first will be used. 
 If there are no pending connections, socket_accept() will block until a connection becomes present. 
 If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned. 
 */

 $msg = "Welcome!<br />";
 //socket_write($msg,$msg,strlen($msg));
 $command = "";

 while(true){
  if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
   echo "錯(cuò)誤(socket_read):".socket_strerror(socket_last_error())."<br />";
   break 2;
  }

  /*
  The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions. 
  The maximum number of bytes read is specified by the length parameter. 
  Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).   
  */

  /*
  if(!$buf = trim($buf))
   continue; // ????

  if($buf == "quit")
   break;

  if($buf == "shutdown"){
   socket_close($msgSocket);
   break 2;
  }

  $tallBack = "You say:$buf\n";
  socket_write($msgSocket,$tallBack,strlen($tallBack));
  */

  if(ord($buf) != 13)
   $command .= $buf;
  else{
   $command1 = "You Say:$command\r\n";
   socket_write($msgSocket,$command1,strlen($command1));
   echo "User typed:".$command."<br />";
   $command = "";
  }
 }
 socket_close($msgSocket);
}

socket_close($socket);
?>

 

然后打開(kāi)CMD,輸入:telnet 192.40.7.93 10000,自己體驗(yàn)去吧!

注,要把:php_sockets.dll 打開(kāi)

相關(guān)文章

  • php中根據(jù)某年第幾天計(jì)算出日期年月日的代碼

    php中根據(jù)某年第幾天計(jì)算出日期年月日的代碼

    在PHP中,使用內(nèi)置的date()函數(shù)很容易得到任意一天是當(dāng)前年的第幾天,格式為date('z'),為此,很多PHP程序會(huì)用一年中的第幾天作為數(shù)據(jù)庫(kù)的索引(index)。
    2011-02-02
  • Yii 2.0中場(chǎng)景的使用教程

    Yii 2.0中場(chǎng)景的使用教程

    這篇文章主要給大家介紹了關(guān)于Yii 2.0中場(chǎng)景使用的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。
    2017-06-06
  • 30 個(gè)很棒的PHP開(kāi)源CMS內(nèi)容管理系統(tǒng)小結(jié)

    30 個(gè)很棒的PHP開(kāi)源CMS內(nèi)容管理系統(tǒng)小結(jié)

    本文匯集了30個(gè)優(yōu)秀的開(kāi)源CMS建站系統(tǒng),采用PHP開(kāi)發(fā)。以下列表不分先后順序
    2011-10-10
  • sphinx增量索引的一個(gè)問(wèn)題

    sphinx增量索引的一個(gè)問(wèn)題

    很早使用coreseek來(lái)實(shí)現(xiàn)對(duì)內(nèi)容的搜索,并使用主索引+增量索引來(lái)實(shí)現(xiàn)新發(fā)的內(nèi)容很快能搜索到,使用一直挺穩(wěn)定。
    2011-06-06
  • Memcache 在PHP中的使用技巧

    Memcache 在PHP中的使用技巧

    Memcache 在PHP中的使用
    2010-02-02
  • PHP對(duì)象Object的概念 介紹

    PHP對(duì)象Object的概念 介紹

    類提供了一個(gè)基礎(chǔ),可以在此基礎(chǔ)上創(chuàng)建實(shí)體(即這個(gè)類所建模的實(shí)體)的特定實(shí)例,這些特定實(shí)例稱為對(duì)象(object)
    2012-06-06
  • PHP基于面向?qū)ο蠓庋b的分頁(yè)類示例

    PHP基于面向?qū)ο蠓庋b的分頁(yè)類示例

    這篇文章主要介紹了PHP基于面向?qū)ο蠓庋b的分頁(yè)類,結(jié)合實(shí)例形式分析了php分頁(yè)類針對(duì)頁(yè)碼判斷、顯示等操作的封裝及分頁(yè)類使用相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • php+mysqli批量查詢多張表數(shù)據(jù)的方法

    php+mysqli批量查詢多張表數(shù)據(jù)的方法

    這篇文章主要介紹了php+mysqli批量查詢多張表數(shù)據(jù)的方法,涉及multi_query、store_result及more_results等函數(shù)的使用技巧,需要的朋友可以參考下
    2015-01-01
  • 淺析php-fpm靜態(tài)和動(dòng)態(tài)執(zhí)行方式的比較

    淺析php-fpm靜態(tài)和動(dòng)態(tài)執(zhí)行方式的比較

    這篇文章主要介紹了php-fpm靜態(tài)和動(dòng)態(tài)執(zhí)行方式的比較,較為詳細(xì)的分析了php-fpm靜態(tài)和動(dòng)態(tài)執(zhí)行方式的原理、參數(shù)功能與相關(guān)使用技巧,需要的朋友可以參考下
    2016-11-11
  • PHP實(shí)現(xiàn)實(shí)時(shí)生成并下載超大數(shù)據(jù)量的EXCEL文件詳解

    PHP實(shí)現(xiàn)實(shí)時(shí)生成并下載超大數(shù)據(jù)量的EXCEL文件詳解

    EXCEL文件的處理是我們?cè)谌粘9ぷ髦薪?jīng)常會(huì)遇到的,這篇文章主要給大家介紹了關(guān)于利用PHP如何實(shí)現(xiàn)實(shí)時(shí)生成并下載超大數(shù)據(jù)量的EXCEL文件,通過(guò)文中介紹的這個(gè)方法對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-10-10

最新評(píng)論

沛县| 岑溪市| 登封市| 时尚| 大新县| 叶城县| 积石山| 阜宁县| 九江市| 鱼台县| 云阳县| 云和县| 剑川县| 繁昌县| 怀安县| 乌审旗| 郑州市| 榆社县| 宽甸| 聊城市| 仁寿县| 浦北县| 岳阳县| 石首市| 靖宇县| 崇义县| 临猗县| 绥滨县| 城固县| 杭锦旗| 邹平县| 深圳市| 武邑县| 乌拉特中旗| 镇远县| 东兴市| 盐亭县| 中卫市| 太谷县| 望江县| 淮阳县|