/**
  * @param string|array $message
  * @param int $mode
  */
 public function send($message, $mode = 0)
 {
     if (false === $this->connected) {
         $connectedTo = $this->socket->getEndpoints();
         if (!in_array($this->dsn, $connectedTo)) {
             $this->socket->connect($this->dsn);
         }
         $this->connected = true;
     }
     $this->socket->send($message, $mode);
 }
示例#2
0
 /**
  * @param $type
  * @throws MQException
  * @return \ZMQSocket
  */
 protected function connection($type)
 {
     /* Create a socket */
     $socket = new \ZMQSocket(new \ZMQContext(), $type);
     /* Get list of connected endpoints */
     $endpoints = $socket->getEndpoints();
     /* Check if the socket is connected */
     if (!in_array($this->dns, $endpoints['connect'])) {
         $socket->connect($this->dns);
         //$socket->bind($this->dns);
     } else {
         throw new MQException("Already connected to {$this->dns}");
     }
     return $socket;
 }