-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws2.php
32 lines (30 loc) · 1.25 KB
/
ws2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require realpath(dirname(__FILE__)).'/bootstrap/autoload.php';
require_once realpath(dirname(__FILE__)).'/bootstrap/start.php';
require realpath(dirname(__FILE__)).'/vendor/autoload.php';
require realpath(dirname(__FILE__)).'/src/chat.php';
require realpath(dirname(__FILE__)).'/app/models/Setting.php';
$port = Setting::getPort();
$pport = Setting::getPPort();
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;
$loop = React\EventLoop\Factory::create();
$chat = new Chat();
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:'.$pport); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($chat, 'onQueue'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen($port, '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(
$chat
)
),
$webSock
);
$loop->run();