Ejemplo n.º 1
0
require APPPATH . "third_party/php-websocket-server/websocket_server.class.php";
class Websocket extends WebSocketServer
{
    public $lastupdate = 0;
    public function onMessage($client, $msg)
    {
        return;
    }
    public function onConnect($client)
    {
        return;
    }
    public function onDisconnect($client)
    {
        return;
    }
    public function onTick($client)
    {
        if ($this->lastupdate < time()) {
            $this->lastupdate = time() + 10;
            //send false as 2ns param to send to all clients
            $client->broadcastData(json_encode((object) array('now' => date('c'))), false);
        }
    }
}
// Configuration variables
$host = 'localhost';
$port = 8888;
$wsServer = new myServer($host, $port);
$wsServer->start();
Ejemplo n.º 2
0
                $client->sendData('You said: ' . $msg);
                $client->broadcastData('<b>' . $client->nick . '</b> #> ' . $msg);
                break;
        }
    }
    public function onConnect($client)
    {
        $client->nick = 'Guest #' . $client->id;
        $client->broadcastData('<b>' . $client->nick . '</b> has connected.');
    }
    public function onDisconnect($client)
    {
        $client->broadcastData('<b>' . $client->nick . '</b> has disconnected.');
    }
}
class myClient extends WebSocketClient
{
    public $nick = 'Guest';
}
// Configuration variables
$host = '10.58.10.175';
$port = 4041;
$wsServer = new myServer($host, $port);
$wsServer->setClientObject('myClient');
$wsServer->start();
// Server functions
function rLog($msg)
{
    $msg = "[" . date('Y-m-d H:i:s') . "] " . $msg;
    print $msg . "\n";
}