示例#1
0
 private function serveUserList()
 {
     $data = array('event' => 'userlist', 'data' => $this->clients);
     response::all(json_encode($data), true);
     $data['client'] = response::$current_socket_key;
     response::me(json_encode($data));
 }
示例#2
0
 protected function event_message($data, $client)
 {
     response::me('hello world, i am the default module!');
 }
                        if (DEBUG) {
                            echo "[DEBUG] client {$sock} disconnecting...\n";
                        }
                        module::dispatch_event('close', false, $sock, array());
                        // close socket
                        socket_close($s);
                        unset($sockets[$sock]);
                        unset($clients[$sock]);
                        //array_splice($sockets, $sock, 1);
                        //array_splice($clients, $sock, 1);
                    } else {
                        if (!$clients[$sock] && web_socket_protocol::is_handshake($str)) {
                            if (DEBUG) {
                                echo "web socket request!\n";
                            }
                            response::me(web_socket_protocol::handshake($str));
                            $clients[$sock] = 'websocket';
                            //flag the client as a web socket client
                        } else {
                            ///TODO create client_data and
                            module::dispatch_event('message', $str, $sock, array());
                        }
                    }
                }
            }
        }
    }
} while (true);
socket_close($listen);
if ($listen_policy) {
    socket_close($listen_policy);