以服務(wù)端模式調(diào)用一個(gè)TCP協(xié)議的OHSCESOCKET資源并啟動(dòng)(監(jiān)聽和響應(yīng))
(OHSCE >=V0.1.9)-以服務(wù)端模式調(diào)用一個(gè)TCP協(xié)議的OHSCESOCKET資源并啟動(dòng)
Ohsce_eng_socket_server_runtcp($Ohsce,$stop=null,$speed=0,$callstop=false)
$ohsce
-待使用的OHSCESOCKET資源。
*必須為TCP類型。
$stop
-最大運(yùn)行環(huán)數(shù)。
NULL為無上限。
$speed
-運(yùn)行速度。0為盡其所能 數(shù)值越大速度越慢
$callstop
-是否允許被呼叫而停止
Example:
$trya='ohsce_server_Example '; function example(&$socket,$buf,$len,$zv){ //收到數(shù)據(jù)時(shí)的回調(diào)函數(shù) global $trya; echo $buf; Ohsce_socketwrite($socket,$trya.'hi '.$buf); return true; } function exampleaccept(&$socket,$ip,$port,$zv){ //新客戶端到訪時(shí)的回調(diào)函數(shù) global $trya; Ohsce_socketwrite($socket,$trya.'Welcome'.$ip.':'.$port); return true; } Ohsce_eng_socket_server($ohsceserver,'tcp',7626,'127.0.0.1','example','exampleaccept');//創(chuàng)建一個(gè)TCP服務(wù)端資源 綁定127.0.0.1:7626 并傳入回調(diào)函數(shù) Ohsce_eng_socket_server_runtcp($ohsceserver); //開始運(yùn)行返回:
當(dāng)被呼叫停止后該函數(shù)返回FALSE
Notice:
默認(rèn)情況下,該函數(shù)只會(huì)監(jiān)聽新訪客/可讀事件。
官方鏈接:http://www.ohsce.com/index.php/book/ohscelib/Ohsceengsocketserverruntcp-10.html
更多建議: