示例#1
0
 /**
  * Connect to server
  *
  * @return boolean
  * @throws StompException
  * @see setVhostname
  */
 public function connect()
 {
     if ($this->isConnected()) {
         return true;
     }
     $this->isConnecting = true;
     $this->connection->connect();
     $this->connection->getParser()->legacyMode(true);
     $this->protocol = new Protocol($this->clientId);
     $this->host = $this->host ?: $this->connection->getHost();
     $connectFrame = $this->protocol->getConnectFrame($this->login, $this->passcode, $this->versions, $this->host);
     $this->sendFrame($connectFrame, false);
     if ($frame = $this->connection->readFrame()) {
         $version = new Version($frame);
         if ($version->hasVersion(Version::VERSION_1_1)) {
             $this->connection->getParser()->legacyMode(false);
         }
         $this->sessionId = $frame['session'];
         $this->protocol = $version->getProtocol($this->clientId);
         $this->isConnecting = false;
         return true;
     }
     throw new ConnectionException('Connection not acknowledged');
 }