コード例 #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);
}
コード例 #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, "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);
コード例 #3
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);
コード例 #4
0
ファイル: socket_server.php プロジェクト: pardoc/FAB-UI
    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);