예제 #1
0
파일: Writer.php 프로젝트: jgswift/qtcp
 public function writePacket(qtcp\Network\Packet $packet, $data = null)
 {
     if (is_array($data)) {
         $packet->setData($data);
     }
     $this->write($packet);
 }
예제 #2
0
파일: Register.php 프로젝트: jgswift/qtcp
 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]));
             }
         }
     });
 }
예제 #3
0
파일: Unregister.php 프로젝트: jgswift/qtcp
 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]);
         }
     });
 }
예제 #4
0
파일: Event.php 프로젝트: jgswift/qtcp
 public function __construct($sender, qtcp\Network\Packet $packet)
 {
     parent::__construct($sender, ['packet' => $packet, 'data' => $packet->getData(), 'id' => $packet->getID()]);
 }