本文整理匯總了PHP中connection::WebSocket方法的典型用法代碼示例。如果您正苦於以下問題:PHP connection::WebSocket方法的具體用法?PHP connection::WebSocket怎麽用?PHP connection::WebSocket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類connection
的用法示例。
在下文中一共展示了connection::WebSocket方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: socket_server
public function socket_server($port)
{
global $sockets, $groups, $master;
$main = new Group();
$main->port = $port;
$main->name = "Main";
$main->members = array();
$main->task = "chat";
array_push($groups, $main);
$master = connection::WebSocket($port);
$sockets = array($master);
while (true) {
$changed = $sockets;
$write = NULL;
$except = NULL;
socket_select($changed, $write, $except, NULL);
foreach ($changed as $socket) {
if ($socket == $master) {
$client_socket = socket_accept($master);
if ($client_socket < 0) {
continue;
} else {
connection::connect($client_socket);
}
} else {
$client = select::bysocket($socket);
$bytes_lenght = socket_recv($socket, $buffer, 2048, 0);
if ($bytes_lenght <= 6) {
connection::disconnect($client);
} else {
if ($client->status < 2) {
connection::dohandshake($client, $buffer);
} else {
$buffer = other::handle_data($buffer);
if ($client->status < 3) {
connection::login($client, $buffer);
} else {
if (true) {
chat::process($client, $buffer);
} else {
//nothing
}
}
}
}
}
}
chat::logm("run\n");
}
}