Blame | Last modification | View Log | RSS feed
#!/usr/bin/php<?php#使用命名空間namespace qbpwcf;#匯入外部套件include("../allInOne.php");/*#提示目前要測試的套件echo "<hr>webSock::registerChatDemo - testCase 1<br>";#涵式說明:#註冊聊天室範例的 passProxy 設定,本函數會用root帳戶去新增.#會在 /etc/httpd/conf/httpd.conf 檔案裡面加上以下內容##Enable the mod_proxy modules in the HTTPD#LoadModule proxy_module modules/mod_proxy.so#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so###ProxyPass##If requeted web address is begin with (ws://hostdns)/wss/chatDemo, then redirect to ws://localhost:8080#ProxyPass /wss/chatDemo ws://localhost:8080#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["rootPasswd"],字串,root帳戶的密碼,預設為"password".#$conf["rootPasswd"]="password";#$conf["httpd.conf"],字串,apache設定檔的路徑與名稱,預設為"/etc/httpd/conf/httpd.conf".#$conf["httpd.conf"]="/etc/httpd/conf/httpd.conf";#備註:#僅能在命令列環境下執行.#參考資料:#用apache的passProxy來識別服務並轉到正確的port=>https://groups.google.com/forum/#!topic/ratchet-php/dj-PgPPO_J0$registerChatDemo=webSock::registerChatDemo($conf);unset($conf);#如果聊天室範例的 passProxy 設定失敗if($registerChatDemo["status"]==="false"){#印出訊息var_dump($registerChatDemo);#結束程式exit;}#if end*//*#提示目前要測試的套件echo "<hr>webSock::chatRoomDemo - testCase 1<br>";#設置資料庫連線密碼Chat::$dbPassword=$dbPassword;#不使用密碼來驗證身份Chat::$passwordCol="";#函數說明:#Ratchet的聊天室伺服端範例,port為8080.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.$conf["disReg"]="true";#參考資料:#Ratchet官網=>http://socketo.me/#聊天室範例=>http://socketo.me/docs/hello-world#備註:#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.#僅適用於http網頁透過ws連線到web socket server.$chatRoomDemo=webSock::chatRoomDemo($conf);unset($conf);#如果執行失敗if($chatRoomDemo["status"]==="false"){#印出結果var_dump($chatRoomDemo);#結束程式exit;}#if end#如果存在 $chatRoomDemo["content"] 則查看結果if(isset($chatRoomDemo["content"])){#印出語法echo $chatRoomDemo["content"];}#if end*//*#提示目前要測試的套件echo "<hr>webSock::chatRoomDemo - testCase 2<br>";#設置資料庫連線密碼ChatV2::$dbPassword=$dbPassword;#不使用密碼來驗證身份ChatV2::$passwordCol="password";#函數說明:#擴充過的Ratchet的聊天室用戶端與伺服端範例第二版,port為8080.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.$conf["disReg"]="true";#參考資料:#Ratchet官網=>http://socketo.me/#聊天室範例=>http://socketo.me/docs/hello-world#備註:#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.#僅適用於http網頁透過ws連線到web socket server.$chatRoomDemoV2=webSock::chatRoomDemoV2($conf);unset($conf);#如果執行失敗if($chatRoomDemoV2["status"]==="false"){#印出結果var_dump($chatRoomDemoV2);#結束程式exit;}#if end#如果存在 $chatRoomDemoV2["content"] 則查看結果if(isset($chatRoomDemoV2["content"])){#印出語法echo $chatRoomDemoV2["content"];}#if end*//*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 1<br>";#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.#$conf["listenIp"]="192.168.200.111";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.$conf["listenPort"]="9999";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];*//*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 2<br>";#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#無#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.#$conf["listenIp"]="192.168.1.105";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.#$conf["listenPort"]="4000";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer();unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];*//*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 3<br>";#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#無#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.$conf["listenIp"]="192.168.1.105";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.#$conf["listenPort"]="4000";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];*//*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 4<br>";#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.#$conf["listenIp"]="127.0.0.1";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.$conf["listenPort"]="4000";#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.$conf["httpMode"]="true";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];*//*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 5<br>";#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.#$conf["listenIp"]="127.0.0.1";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.$conf["listenPort"]="4000";#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.#$conf["httpMode"]="true";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];*/#/*#提示目前要測試的套件echo "<hr>webSock::nativeSocketTcpipServer - testCase 6<br>";echo PHP_EOL;#函式說明:#建立php原生的socket#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["fileArgu"],字串,變數__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["listenIp"],字串,要接聽的主機ip,預設為本機的ip.#$conf["listenIp"]="127.0.0.1";#$conf["listenPort"],字串,要接聽的port,預設為已使用port+1.$conf["listenPort"]="4000";#$conf["httpMode"],字串,是否要用http模式,預設為"false",不使用,若為"true"則要使用.$conf["httpMode"]="true";#參考資料:#http://php.net/manual/en/sockets.examples.php#備註:#僅能在命令列執行#建構中...$nativeSocketTcpipServer=webSock::nativeSocketTcpipServer($conf);unset($conf);#如果建立 socket 服務失敗if($nativeSocketTcpipServer["status"]==="false"){#印出內容var_dump($nativeSocketTcpipServer);#結束程式exit;}#if end#印出結果echo $nativeSocketTcpipServer["status"];#*//*#提示目前要測試的套件echo "<hr>webSock::connectNativeSocket - testCase 1<br>";#函數說明:#連線到函數createNativeSocket建立的socket.#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["content"],取得的回應.y#$result["argu"],所使用的參數.#必填參數:#無.#可省略參數:#$conf["targetServr"],字串,要連線的目標,預設為"localhost".#$conf["targetServr"]="";#$conf["targetPort"],字串,要連線的目標port,預設為"80"port.#$conf["targetPort"]="";#備註:#建構中...$connectNativeSocket=webSock::connectNativeSocket();#如果建立socket連線失敗if($connectNativeSocket["status"]==="false"){#印出內容var_dump($connectNativeSocket);#結束程式exit;}#if end#印出取得的回應echo $connectNativeSocket["content"];*//*#提示目前要測試的套件echo "<hr>webSock::connectNativeSocket - testCase 2<br>";#函數說明:#連線到函數createNativeSocket建立的socket.#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["content"],取得的回應.y#$result["argu"],所使用的參數.#必填參數:#無.#可省略參數:#$conf["targetServr"],字串,要連線的目標,預設為"localhost".#$conf["targetServr"]="";#$conf["targetPort"],字串,要連線的目標port,預設為"80"port.$conf["targetPort"]="4000";#備註:#建構中...$connectNativeSocket=webSock::connectNativeSocket($conf);#如果建立socket連線失敗if($connectNativeSocket["status"]==="false"){#印出內容var_dump($connectNativeSocket);#結束程式exit;}#if end#印出取得的回應echo $connectNativeSocket["content"];*//*#提示目前要測試的套件echo "<hr>webSock::client - testCase 1<br>";#函式說明:#webSocket的用戶端#回傳結果:#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.#$result["error"],錯誤訊息陣列.#$resutl["function"],當前執行的涵式名稱.#$result["argu"],所使用的參數.#必填參數:#$conf["url"],字串要拜訪的web socket,請省略"ws://".$conf["url"]="127.0.0.1:8080";#可省略參數:#$conf["entry"],字串,是否要用加密的wss,預設為"false",代表用ws,若為"true"則為ws.#$conf["entry"]="false";#$conf["connVar"],字串,用來儲存webSocket連線的物件名稱,預設為"conn".#$conf["connVar"]="conn";#備註:#建構中...$client=webSock::client($conf);unset($conf);#如果建立web socket client 失敗if($client["status"]==="false"){#印出錯誤訊息var_dump(client);#結束程式exit;}#if end#印出內容echo $client["content"];*//*#提示目前要測試的套件echo "<hr>webSock::soldierDemo - testCase 1<br>";#設置資料庫連線密碼soldier::$dbPassword=$dbPassword;soldier::$dbName="qbpwcf";#函數說明:#擴充過的Ratchet的聊天室soilier用戶端與伺服端範例,port為8080.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.$conf["disReg"]="true";#參考資料:#Ratchet官網=>http://socketo.me/#聊天室範例=>http://socketo.me/docs/hello-world#備註:#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.#僅適用於https網頁透過wss連線到web socket server.$soldierDemo=webSock::soldierDemo($conf);#如果執行失敗if($soldierDemo["status"]==="false"){#印出結果var_dump($soldierDemo);#結束程式exit;}#if end#如果存在 $soldierDemo["content"] 則查看結果if(isset($soldierDemo["content"])){#印出語法echo $soldierDemo["content"];}#if end*//*#提示目前要測試的套件echo "<hr>webSock::soldierDemo - testCase 1<br>";#設置資料庫連線密碼ChatV3::$dbPassword=$dbPassword;#函數說明:#擴充過的Ratchet的聊天室用戶端與伺服端範例第三版,port為8080.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],字串,__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["disReg"],字串,是否要取消apache的passProxy檢查與設定,預設為"false"不取消,"true"為取消.$conf["disReg"]="true";#參考資料:#Ratchet官網=>http://socketo.me/#聊天室範例=>http://socketo.me/docs/hello-world#備註:#必須要在命令列環境下執行一次,建立webSocket Server後,再於網頁端執行即可產生webSocket Client端的code.#僅適用於https網頁透過wss連線到web socket server.$chatRoomDemoV3=webSock::chatRoomDemoV3($conf);#如果建立chat room v3失敗if($chatRoomDemoV3["status"]==="false"){#印出內容var_dump($chatRoomDemoV3);#結束程式exit;}#if end#如果存在 $chatRoomDemoV3["content"] 則查看結果if(isset($chatRoomDemoV3["content"])){#印出語法echo $chatRoomDemoV3["content"];}#if end*//*#提示目前要測試的套件echo "<hr>webSock::soldierServerDemo - testCase 1<br>";#設置資料庫名稱soldier::$dbName="qbpwcf";#設置資料庫連線密碼soldier::$dbPassword=$dbPassword;#函數說明:#擴充過的Ratchet聊天室伺服端soldier範例,port為8080.#回傳結果:#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.#$reuslt["error"],執行不正常結束的錯訊息陣列.#$result["function"],當前執行的函式名稱.#必填參數:#$conf["fileArgu"],__FILE__的內容.$conf["fileArgu"]=__FILE__;#可省略參數:#$conf["port"],要 listen 的 port$conf["port"]=8888;#參考資料:#Ratchet官網=>http://socketo.me/#聊天室範例=>http://socketo.me/docs/hello-world#備註:#必須要在命令列環境下執行才行.webSock::soldierServerDemo($conf);unset($conf);*/?>