Example #1
0
 /**
  *
  */
 public function send()
 {
     foreach ($this->messageBuffer as $message) {
         $this->socket->send($message);
     }
     $this->messageBuffer = [];
     $this->messageBufferSize = 0;
 }
Example #2
0
 /**
  * @param string $id
  * @param string $type
  * @param mixed $message
  * @param int $flags
  * @return bool
  */
 private function sendMessage($id, $type, $message = null, $flags = self::MODE_STANDARD)
 {
     if (($frame = $this->getFrame($id, $type, $message)) === null) {
         return false;
     }
     $isConnected = $this->isConnected();
     if (!$isConnected) {
         if ($this->flags['enableBuffering'] === true && ($flags & self::MODE_BUFFER_OFFLINE) === self::MODE_BUFFER_OFFLINE) {
             return $this->buffer->add($frame);
         }
     } else {
         if ($type === self::COMMAND_HEARTBEAT) {
             if ($this->socket->closed === false && $this->socket->send($frame)) {
                 $this->connectionPool->registerHeartbeat($id);
                 return true;
             }
         } else {
             if ($this->flags['enableHeartbeat'] === false || $this->flags['enableBuffering'] === true && ($flags & self::MODE_BUFFER_ONLINE) === self::MODE_BUFFER_ONLINE || $this->connectionPool->validateConnection($id) === true) {
                 $this->socket->send($frame);
                 $this->connectionPool->registerHeartbeat($id);
                 return true;
             }
         }
     }
     return false;
 }