PHP Classes

File: websocket/bin/chat-server.php

Recommend this page to a friend!
  Classes of Will Tinsdeall   Boiler Framework   websocket/bin/chat-server.php   Download  
File: websocket/bin/chat-server.php
Role: Example script
Content type: text/plain
Description: Auxiliary script
Class: Boiler Framework
Web application framework that implements MVC
Author: By
Last change:
Date: 9 years ago
Size: 981 bytes
 

Contents

Class file image Download
<?php
   
require dirname(__DIR__) . '/vendor/autoload.php';

   
$loop = React\EventLoop\Factory::create();
   
$pusher = new MyApp\Pusher;

   
// Listen for the web server to make a ZeroMQ push after an ajax request
   
$context = new React\ZMQ\Context($loop);
   
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
   
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
   
$pull->on('message', array($pusher, 'onServerPush'));

   
// Set up our WebSocket server for clients wanting real-time updates
   
$webSock = new React\Socket\Server($loop);
   
$webSock->listen(82, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
   
$webServer = new Ratchet\Server\IoServer(
        new
Ratchet\Http\HttpServer(
            new
Ratchet\WebSocket\WsServer(
                new
Ratchet\Wamp\WampServer(
                   
$pusher
               
)
            )
        ),
       
$webSock
   
);

   
$loop->run();