Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $loop = Factory::create();
- $pusher = new Notification();
- $context = new Context($loop);
- $pull = $context->getSocket(ZMQ::SOCKET_PULL);
- $webSock = new Server('127.0.0.1:8080', $loop);
- $pull->bind('tcp://127.0.0.1:5555');
- $pull->on('message', array($pusher, 'onTest'));
- $webServer = new IoServer(
- new HttpServer(
- new WsServer(
- new Notification()
- )
- ),
- $webSock
- );
- $loop->run();
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $context = new ZMQContext();
- $socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'onTest');
- $socket->connect('tcp://localhost:5555');
- $socket->send('Test message');
- }
- class Notification implements MessageComponentInterface
- {
- protected $clients;
- public function __construct()
- {
- $this->clients = new SplObjectStorage();
- }
- public function onOpen(ConnectionInterface $conn)
- {
- $this->clients->attach($conn);
- }
- public function onClose(ConnectionInterface $conn)
- {
- $this->clients->detach($conn);
- }
- public function onError(ConnectionInterface $conn, Exception $e)
- {
- $conn->close();
- }
- public function onMessage(ConnectionInterface $from, $msg)
- {
- //auth user etc
- }
- public function onTest($entry)
- {
- //this array is always empty
- foreach ($this->clients as $client) {
- $client->send('send new message');
- }
- }
- }
Add Comment
Please, Sign In to add comment