Esempio n. 1
0
function wsStart()
{
    // start the server
    $Server = new PHPWebSocket();
    $Server->bind('message', 'wsOnMessage');
    $Server->bind('open', 'wsOnOpen');
    $Server->bind('close', 'wsOnClose');
    // for other computers to connect, you will probably need to change this to your LAN IP or external IP,
    // alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
    $Server->wsStartServer('128.30.53.32', 9300);
}
Esempio n. 2
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has joined the room.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('localhost', 8000);
Esempio n. 3
0
    if (method_exists($Factory, $function)) {
        $message = $Factory->{$function}($data);
    }
    // > 1 cause monitor.py is always connected
    if ($Server->wsGetClientsNumber() > 0) {
        //Send the message to everyone but the person who said it
        foreach ($Server->wsClients as $id => $client) {
            //if ($id != $clientID) {
            //$clientIp = long2ip($client[6]);
            //echo $clientIp.PHP_EOL;
            $Server->wsSend($id, $message);
            //}
        }
    }
}
// when a client connects
function wsOnOpen($clientID)
{
    //echo $clientID . " connected" . PHP_EOL;
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    //echo $clientID . " disconnected" . PHP_EOL;
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
//$Server -> bind('open', 'wsOnOpen');
//$Server -> bind('close', 'wsOnClose');
$Server->wsStartServer(SOCKET_HOST, SOCKET_PORT);
Esempio n. 4
0
    if (array_key_exists('SERVER_ADDR', $_SERVER)) {
        return $_SERVER['SERVER_ADDR'];
    } elseif (array_key_exists('LOCAL_ADDR', $_SERVER)) {
        return $_SERVER['LOCAL_ADDR'];
    } elseif (array_key_exists('SERVER_NAME', $_SERVER)) {
        return gethostbyname($_SERVER['SERVER_NAME']);
    } else {
        // Running CLI
        if (stristr(PHP_OS, 'WIN')) {
            return gethostbyname(php_uname("n"));
        } else {
            $ifconfig = shell_exec('/sbin/ifconfig eth0');
            preg_match('/addr:([\\d\\.]+)/', $ifconfig, $match);
            return $match[1];
        }
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
$game_controller = new GameController($Server);
//var_dump($game_controller);
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
//$Server->wsStartServer('192.168.0.42', 9301);
$ipAddress = getServerAddress();
$port = "9301";
echo "Server start at " . $ipAddress . ":" . $port;
$Server->wsStartServer($ipAddress, $port);
Esempio n. 5
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has joined the room.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('127.0.0.1', 9300);
Esempio n. 6
0
    $wsRead = var_dump($Server->wsRead);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has joined the room. ---- {$client}");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('192.168.11.100', 9700);
sleep(10);
echo 'shutting down';
$Server->wsShutdownServer();
Esempio n. 7
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, json_encode(array('user' => array('id' => $clientID, 'ip' => $ip), 'status' => 'connect', 'msg' => '')));
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, json_encode(array('user' => $arrayName = array('id' => $clientID, 'ip' => $ip), 'status' => 'disconnect', 'msg' => '')));
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer($config["server"], $config["port"]);
Esempio n. 8
0
                //$Servidor->wsSend($id, '<b>'.$nome_pessoa.':</b> <i>'.$mensagem.'</i>');
                $Servidor->wsSend($id, '<b>Integrante ' . $integranteID . ':</b> <i>' . $mensagem . '</i>');
            }
        }
    }
}
function EntrarNoChat($integranteID)
{
    global $Servidor;
    $ip = long2ip($Servidor->wsClients[$integranteID][6]);
    $nome_pessoa = $Servidor->wsClients[$integranteID][12];
    foreach ($Servidor->wsClients as $id => $integrante) {
        if ($id != $integranteID) {
            $Servidor->wsSend($id, '<b>Servidor:</b> <i>O integrante ' . $integranteID . ' (' . $ip . ') entrou no chat</i>');
        }
    }
}
function SairDoChat($integranteID, $status)
{
    global $Servidor;
    $ip = long2ip($Servidor->wsClients[$integranteID][6]);
    $nome_pessoa = $Servidor->wsClients[$integranteID][12];
    foreach ($Servidor->wsClients as $id => $integrante) {
        $Servidor->wsSend($id, '<b>Servidor:</b> <i>O integrante ' . $integranteID . ' (' . $ip . ') saiu do chat</i>.');
    }
}
$Servidor = new PHPWebSocket();
$Servidor->bind('message', 'EnviarMensagem');
$Servidor->bind('open', 'EntrarNoChat');
$Servidor->bind('close', 'SairDoChat');
$Servidor->wsStartServer('31.170.164.119', 9300);
Esempio n. 9
0
{
	global $Server;
	$ip = long2ip( $Server->wsClients[$clientID][6] );

	$Server->log( "" );

	//Send a join notice to everyone but the person who joined
	foreach ( $Server->wsClients as $id => $client )
		if ( $id != $clientID )
			$Server->wsSend($id, "");
}

// when a client closes or lost connection
function wsOnClose($clientID, $status) {
	global $Server;
	$ip = long2ip( $Server->wsClients[$clientID][6] );

	$Server->log( "" );

	foreach ( $Server->wsClients as $id => $client )
		$Server->wsSend($id, "");
}

$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');

$Server->wsStartServer('192.168.1.71',12345);

?>
Esempio n. 10
0
{
	global $Server;
	$ip = long2ip( $Server->wsClients[$clientID][6] );

	$Server->log( "" );

	//Send a join notice to everyone but the person who joined
	foreach ( $Server->wsClients as $id => $client )
		if ( $id != $clientID )
			$Server->wsSend($id, "");
}

// when a client closes or lost connection
function wsOnClose($clientID, $status) {
	global $Server;
	$ip = long2ip( $Server->wsClients[$clientID][6] );

	$Server->log( "" );

	foreach ( $Server->wsClients as $id => $client )
		$Server->wsSend($id, "");
}

$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');

$Server->wsStartServer('45.55.90.254',5555);

?>
Esempio n. 11
0
    $Server->log("{$ip} ({$clientID}) esta conectado.");
    //Send a join notice to everyone but the person who joined
    //foreach ( $Server->wsClients as $id => $client )
    //	if ( $id != $clientID )
    //		$Server->wsSend($id, "Visitante $clientID ($clientID) Se ha unido al chat.");
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) Esta conectado.");
    //enviar mensaje de desconexion
    $mensaje = new mensaje();
    $mensaje->tx = $Server->wsClients[$clientID][12];
    $mensaje->msg = "se desconecto " . $clientID;
    $mensaje->tipo = 3;
    $message = json_encode($mensaje);
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, $message);
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('75.98.173.239', 9300);
Esempio n. 12
0
    $Server->log(" ({$clientID}) se ha conectado.");
    //$Server->log( "$ip ($clientID) has connected." );
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
        }
    }
    //$Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.");
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //$Server->log( "$ip ($clientID) has disconnected." );
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
    }
    //$Server->wsSend($id, "El visitante $clientID ha salido de la charla.");
    //$Server->wsSend($id, "El visitante $clientID ($ip) ha salido de la charla.");
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
//$Server->wsStartServer('127.0.0.1', 8000);
$Server->wsStartServer('ws://dotredes.dyndns.biz', 0);
Esempio n. 13
0
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has joined the room.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
function randomFact()
{
    $xml = simplexml_load_string(file_get_contents('data.xml'));
    return trim($xml->fact[rand(1, sizeof($xml))]);
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
//$Server->wsStartServer('127.0.0.1', 9300);
//$Server->wsStartServer('192.168.0.52', 9300);
$Server->wsStartServer(getHostByName(getHostName()), 8081);
Esempio n. 14
0
{
    echo $clientID;
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log(_("Someone has connected."));
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, _("Someone has joined the room."));
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log(_("Someone has disconnected."));
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, _("Someone has left the room."));
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer($sysconf['chat_system']['server'], $sysconf['chat_system']['server_port']);
Esempio n. 15
0
    //	//Send a join notice to everyone but the person who joined
    //	foreach ( $Server->wsClients as $id => $client ){
    //		if ( $id != $clientID ){
    //			$Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.<br>");
    //
    //		}
    //	}
    //
    //	if(!empty($listUsers)){
    //		$Server->wsSend($clientID, "You are connected");
    //	}
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer(HOST, PORT);
Esempio n. 16
0
{
    if (strlen($str) == 3) {
        return ord($str[0]) * 16384 + ord($str[1]) * 128 + ord($str[2]);
    } else {
        return false;
    }
}
function fromUint28($str)
{
    if (strlen($str) == 4) {
        return ord($str[0]) * 2097152 + ord($str[1]) * 16384 + ord($str[2]) * 128 + ord($str[3]);
    } else {
        return false;
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
// or [WORKING] gethostbyname(gethostname())
//$Server->wsStartServer('0.0.0.0', 8399); //All
//$Server->wsStartServer('69.174.53.19', 8399); // InMotion VPS
$Server->wsStartServer(gethostbyname(gethostname()), 8399);
// Dynamic. Make sure ports are forwarded ON CORRECT IP for this machine. Normally would use $_SERVER['REMOTE_ADDR'] on web apps
//Deprecated server addresses
//$Server->wsStartServer('127.0.0.1', 8399); //Local
//$Server->wsStartServer('192.168.0.3', 8399); //Dorms
//$Server->wsStartServer('192.168.1.101', 8399); //Ron
Esempio n. 17
0
        }
    }
}
// when a client connects
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("Socket abierto");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("");
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "");
    }
}
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
$Server->wsStartServer('192.168.43.187', 8080);
Esempio n. 18
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has joined the room.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID} ({$ip}) has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('codebase.in', 9300);
Esempio n. 19
0
        if (!defined('sugarEntry')) {
            define('sugarEntry', true);
        }
        $root_dir = dirname(dirname(__DIR__));
        chdir($root_dir);
        require_once $root_dir . '/config.php';
        $GLOBALS['db_cfg'] = $sugar_config['dbconfig'];
        $GLOBALS['db'] = mysql_connect($GLOBALS['db_cfg']['db_host_name'], $GLOBALS['db_cfg']['db_user_name'], $GLOBALS['db_cfg']['db_password']);
        mysql_select_db($GLOBALS['db_cfg']['db_name'], $GLOBALS['db']) or die('Can`t connect to db ' . mysql_error());
        query('SET names utf8');
    }
}
function fetchAssoc($object)
{
    return mysql_fetch_assoc($object);
}
function query($q)
{
    $r = mysql_query($q) or die('SQL error ' . $q . ', err:' . mysql_error());
    return $r;
}
$db = false;
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
// $Server->wsStartServer('127.0.0.1', 9300);
$Server->wsStartServer('82.146.52.49', 31130);
Esempio n. 20
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Screen {$clientID} ({$ip}) has joined the server.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Screen {$clientID} ({$ip}) has left the server.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer('192.168.1.103', 9300);
Esempio n. 21
0
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has connected.");
    //Send a join notice to everyone but the person who joined
    foreach ($Server->wsClients as $id => $client) {
        if ($id != $clientID) {
            $Server->wsSend($id, "Visitor {$clientID}  has joined the room.");
        }
    }
}
// when a client closes or lost connection
function wsOnClose($clientID, $status)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $Server->log("{$ip} ({$clientID}) has disconnected.");
    //Send a user left notice to everyone in the room
    foreach ($Server->wsClients as $id => $client) {
        $Server->wsSend($id, "Visitor {$clientID}  has left the room.");
    }
}
// start the server
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
// for other computers to connect, you will probably need to change this to your LAN IP or external IP,
// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))
$Server->wsStartServer(SERVERip, SERVERport);