Esempio n. 1
0
 /**
  * Events listener for connection data
  */
 public function onConnectionData(Event $event, $connection)
 {
     $this->buffer .= $event->getData();
     try {
         $parsed = mb_strlen($this->buffer) ? $this->tryParse($this->buffer) : false;
     } catch (\Exception $e) {
         $this->trigger("error", $e->getMessage());
         return;
     }
     if ($parsed) {
         $this->buffer = "";
         $connection->off("data", [$this, "onConnectionData"]);
         $this->trigger("read-complete");
     }
 }
Esempio n. 2
0
 public function onData(Event $event)
 {
     $this->messages .= $data = $event->getData();
     $i = 0;
     while (false !== ($msg = $this->extractMessage())) {
         $i++;
         $eventObject = unserialize($msg);
         foreach ($this->listeners as $listener) {
             $listener->trigger($eventObject);
         }
     }
     if ($this->messages && !$i) {
         $msg = $this->messages;
         if (strlen($msg) < 100) {
             $msg = "0x" . bin2hex($msg);
         }
         log::error("Got broken message:\n{$msg}");
         log::error("last data: " . var_export($data, 1));
     }
 }