| Line 78... |
Line 78... |
| 78 |
|
78 |
|
| 79 |
#印出指令說明
|
79 |
#印出指令說明
|
| 80 |
echo "Usage of ".basename(__FILE__).":".PHP_EOL;
|
80 |
echo "Usage of ".basename(__FILE__).":".PHP_EOL;
|
| 81 |
echo "--addr 代表 Server 要 Listen 的 address".PHP_EOL;
|
81 |
echo "--addr 代表 Server 要 Listen 的 address".PHP_EOL;
|
| 82 |
echo "--port 代表 Server 要 Listen 的 port".PHP_EOL;
|
82 |
echo "--port 代表 Server 要 Listen 的 port".PHP_EOL;
|
| - |
|
83 |
echo "--debug 代表 Server 是否要顯示 debug 訊息,\"on\"代表要,預設為\"off\".".PHP_EOL;
|
| 83 |
|
84 |
|
| 84 |
#結束執行
|
85 |
#結束執行
|
| 85 |
exit;
|
86 |
exit;
|
| 86 |
|
87 |
|
| 87 |
}#function help end
|
88 |
}#function help end
|
| Line 116... |
Line 117... |
| 116 |
#結束執行
|
117 |
#結束執行
|
| 117 |
exit;
|
118 |
exit;
|
| 118 |
|
119 |
|
| 119 |
}#if end
|
120 |
}#if end
|
| 120 |
|
121 |
|
| 121 |
#如果沒有 addr 參數
|
- |
|
| 122 |
if(!isset($parseArgu["content"]["addr"])){
|
- |
|
| 123 |
|
- |
|
| 124 |
#讀取設定檔的 addr 設定
|
- |
|
| 125 |
$parseArgu["content"]["addr"][0]=webSocketServerDefaultListenAddr;
|
- |
|
| 126 |
|
- |
|
| 127 |
}#if end
|
- |
|
| 128 |
|
- |
|
| 129 |
#如果沒有 port 參數
|
- |
|
| 130 |
if(!isset($parseArgu["content"]["port"])){
|
- |
|
| 131 |
|
- |
|
| 132 |
#讀取設定檔的 port 設定
|
- |
|
| 133 |
$parseArgu["content"]["port"][0]=webSocketServerDefaultListenPort;
|
- |
|
| 134 |
|
- |
|
| 135 |
}#if end
|
- |
|
| 136 |
|
- |
|
| 137 |
#檢查參數
|
122 |
#檢查參數
|
| 138 |
#函式說明:
|
123 |
#函式說明:
|
| 139 |
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
|
124 |
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
|
| 140 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
125 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 141 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
126 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
| Line 165... |
Line 150... |
| 165 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
150 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
| 166 |
#$conf["canBeEmpty"]=array();
|
151 |
#$conf["canBeEmpty"]=array();
|
| 167 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
152 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
| 168 |
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
|
153 |
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
|
| 169 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
154 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 170 |
$conf["skipableVariableName"]=array("addr","port");
|
155 |
$conf["skipableVariableName"]=array("addr","port","debug");
|
| 171 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
156 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 172 |
$conf["skipableVariableType"]=array("array","array");
|
157 |
$conf["skipableVariableType"]=array("array","array","array");
|
| 173 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
158 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 174 |
$conf["skipableVarDefaultValue"]=array(array("127.0.0.1"),array("8080"));
|
159 |
$conf["skipableVarDefaultValue"]=array(array(webSocketServerDefaultListenAddr),array(webSocketServerDefaultListenPort),array("off"));
|
| 175 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
160 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
| 176 |
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
|
161 |
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
|
| 177 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
162 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
| 178 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
163 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
| 179 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
164 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
| Line 206... |
Line 191... |
| 206 |
}#if end
|
191 |
}#if end
|
| 207 |
|
192 |
|
| 208 |
#取得各項參數
|
193 |
#取得各項參數
|
| 209 |
$addr=$parseArgu["content"]["addr"][0];
|
194 |
$addr=$parseArgu["content"]["addr"][0];
|
| 210 |
$port=$parseArgu["content"]["port"][0];
|
195 |
$port=$parseArgu["content"]["port"][0];
|
| - |
|
196 |
$debug=$parseArgu["content"]["debug"][0];
|
| - |
|
197 |
|
| - |
|
198 |
#如果為 "on"
|
| - |
|
199 |
if($debug==="on"){
|
| - |
|
200 |
|
| - |
|
201 |
#設置為"true"
|
| - |
|
202 |
$debug="true";
|
| - |
|
203 |
|
| - |
|
204 |
}#if end
|
| - |
|
205 |
|
| - |
|
206 |
#反之
|
| - |
|
207 |
else{
|
| - |
|
208 |
|
| - |
|
209 |
#設置為"false"
|
| - |
|
210 |
$debug="false";
|
| - |
|
211 |
|
| - |
|
212 |
}#else end
|
| 211 |
|
213 |
|
| 212 |
#函式說明:
|
214 |
#函式說明:
|
| 213 |
#建立php原生的socket tcp/ip server,進而實作webSocket
|
215 |
#建立php原生的socket tcp/ip server,進而實作webSocket
|
| 214 |
#回傳結果:
|
216 |
#回傳結果:
|
| 215 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
217 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
| Line 228... |
Line 230... |
| 228 |
$conf["wsMode"]="true";
|
230 |
$conf["wsMode"]="true";
|
| 229 |
#$conf["processFuncs"],陣列,針對收到的訊息要呼叫的函式,會帶入一個參數陣列,array("data"=>收到的資料,"serverSock"=>serverSock,"clientSock"=>clientSock,"clientInfo"=>用戶端的資訊,"clientIndex"=>用戶端的索引,"allConn"=>所有連線的用戶端的連線資訊),回傳的結果若為陣列$result,其$result["status"]為"true"時,會結束執行(等待下個訊息);為"false"時,會var_dump結果,然後交給下一個函式執行;為"continue"時,代表交給下一個函式執行;預設的數值為array("noAuth");
|
231 |
#$conf["processFuncs"],陣列,針對收到的訊息要呼叫的函式,會帶入一個參數陣列,array("data"=>收到的資料,"serverSock"=>serverSock,"clientSock"=>clientSock,"clientInfo"=>用戶端的資訊,"clientIndex"=>用戶端的索引,"allConn"=>所有連線的用戶端的連線資訊),回傳的結果若為陣列$result,其$result["status"]為"true"時,會結束執行(等待下個訊息);為"false"時,會var_dump結果,然後交給下一個函式執行;為"continue"時,代表交給下一個函式執行;預設的數值為array("noAuth");
|
| 230 |
#$conf["processFuncs"]=array("\qbpwcf\callFunc");
|
232 |
#$conf["processFuncs"]=array("\qbpwcf\callFunc");
|
| 231 |
#$conf["idleFunc"],陣列,當沒有收到訊息時,要執行的函式順序,預設不指定.
|
233 |
#$conf["idleFunc"],陣列,當沒有收到訊息時,要執行的函式順序,預設不指定.
|
| 232 |
#$conf["idleFunc"]=array();
|
234 |
#$conf["idleFunc"]=array();
|
| - |
|
235 |
#$conf["debug"],字串,"true"代表要輸出debug訊息;反之預設為"false".
|
| - |
|
236 |
$conf["debug"]=$debug;
|
| 233 |
#參考資料:
|
237 |
#參考資料:
|
| 234 |
#http://php.net/manual/en/sockets.examples.php
|
238 |
#http://php.net/manual/en/sockets.examples.php
|
| 235 |
#http://us3.php.net/manual/en/function.socket-select.php
|
239 |
#http://us3.php.net/manual/en/function.socket-select.php
|
| 236 |
#response should at least end with "\r"=>http://stackoverflow.com/questions/25739768/websocket-communication-between-chromeclient-and-hotspotserver-status-line
|
240 |
#response should at least end with "\r"=>http://stackoverflow.com/questions/25739768/websocket-communication-between-chromeclient-and-hotspotserver-status-line
|
| 237 |
#response status code should be 101=>http://stackoverflow.com/questions/29829597/i-get-a-status-200-when-connecting-to-the-websocket-but-it-is-an-error
|
241 |
#response status code should be 101=>http://stackoverflow.com/questions/29829597/i-get-a-status-200-when-connecting-to-the-websocket-but-it-is-an-error
|