Ejemplo n.º 1
0
 public function writePacket(qtcp\Network\Packet $packet, $data = null)
 {
     if (is_array($data)) {
         $packet->setData($data);
     }
     $this->write($packet);
 }
Ejemplo n.º 2
0
 function __construct($data = null)
 {
     parent::__construct($data);
     $this->attach('receive', function ($client, $e) {
         $app = $client->getApplication();
         $timers = $client->getTimers();
         $wrappers = $app->getWrappers();
         foreach ($wrappers as $w) {
             $id = $w->getID();
             $name = $w->getName();
             if ($id == $e['data'][0]) {
                 $stream = $w->createStream(qio\Stream\Mode::Read);
                 $reader = $w->createReader($stream);
                 $stream->open();
                 //$stream->lock();
                 $value = $reader->readAll();
                 $stream->close();
                 $timer = new qtcp\Application\BubbleTimer(0.1, function () use($reader, $stream, $client, $id, $name) {
                     $stream->open();
                     $stream->seek(0);
                     $value = $reader->readAll();
                     $client->send(new Tell(), [$id, $name, $value]);
                     $stream->close();
                 });
                 $timers->insert($id, $timer);
                 $app->clock->addTimer($timer);
                 $timer->start();
                 $client->send(new self(), [$id, $w->getName()]);
                 $client->send(new Tell([$id, $name, $value]));
             }
         }
     });
 }
Ejemplo n.º 3
0
 function __construct($data = null)
 {
     parent::__construct($data);
     $this->attach('receive', function ($client, $e) {
         $app = $client->getApplication();
         $timers = $client->getTimers();
         $id = $e['data'][0];
         $wrappers = $app->getWrappers();
         if (isset($timers[$id])) {
             $timer = $timers[$id];
             $name = null;
             if ($wrappers->exists($id)) {
                 $name = $wrappers[$id]->getName();
             }
             $app->clock->removeTimer($timer);
             $client->getTimers()->remove($id);
             $client->send(new self(), [$id, $name]);
         }
     });
 }
Ejemplo n.º 4
0
 public function __construct($sender, qtcp\Network\Packet $packet)
 {
     parent::__construct($sender, ['packet' => $packet, 'data' => $packet->getData(), 'id' => $packet->getID()]);
 }