// package manager. Once installed and available, you // need to install the "cboden/ratchet" dependencies (2) // -- // (1) https://getcomposer.org // (2) http://socketo.me/docs/install require dirname(__DIR__) . '/vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use MyApp\Chat; use MyApp\Logger; // $logger is our interface to SYSLOG services. We use it to LOG chat-server // activities... to SYSLOG (so to be able to "tail -f syslog" to check what's going on) $logger = new Logger(); $logger->SetDetails(false); $logger->SetLevel(LOG_DEBUG); // $loop is our main event-loop object $logger->debug('Instantiating main loop object'); $loop = React\EventLoop\Factory::create(); // $chat is our main object, handling communications // with connected browsers, via websockets; $logger->debug('Instantiating main Chat object'); $chat = new Chat(); // this is our TCP-server that will receive messages // to be delivered to clients/browsers via websocket; $logger->debug('Instantiating main "Server" socket object'); $server = new React\Socket\Server($loop); // Let's define some very-basic code to be run when something is // received on the main socket (the one supposed to RECEIVE the // data to be sent to websocket clients... $logger->debug('Setting [onConnection/onData] callback');
// this PHP application require the Composer (1) PHP // package manager. Once installed and available, you // need to install the "cboden/ratchet" dependencies (2) // -- // (1) https://getcomposer.org // (2) http://socketo.me/docs/install require dirname(__DIR__) . '/vendor/autoload.php'; use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use MyApp\Chat; use MyApp\Logger; $logger = new Logger(); $logger->SetDetails(false); $logger->SetLevel(LOG_INFO); // main event-loop objects $logger->debug('Instantiating main loop object'); $loop = React\EventLoop\Factory::create(); // this is our main object, handling communications // with connected browsers, via websockets; $logger->debug('Instantiating main Chat object'); $chat = new Chat(); // this is our TCP-server that will receive messages // to be delivered to clients/browsers via websocket; $logger->debug('Instantiating main "Server" socket object'); $server = new React\Socket\Server($loop); // Let's define some very-basic code to be run when something is // received on the main socket (the one supposed to RECEIVE the // data to be sent to websocket clients... $logger->debug('Setting [onConnection/onData] callback');