Example #1
0
 protected function _connect()
 {
     $connect_params = array('accept-version' => '1.0,1.1,1.2', 'heart-beat' => '0,0');
     $accepted_headers = array('host', 'login', 'passcode');
     foreach ($accepted_headers as $header) {
         if (isset($this->_connect_options[$header])) {
             $connect_params[$header] = $this->_connect_options[$header];
         }
     }
     $connect_frame = new Frame(Frame::COMMAND_CONNECT, '', $connect_params);
     $this->_connection->write($connect_frame);
     if ($response = $this->_connection->readFrame()) {
         $this->_server_info = $response->getHeaders();
     } else {
         throw new ConnectionException('No response from server.');
     }
 }
Example #2
0
 /**
  * Connection has data to read.
  *
  * @return boolean
  * @deprecated use $client->getConnection()
  */
 public function hasFrameToRead()
 {
     return $this->connection->hasDataToRead();
 }
Example #3
0
 public function testConnectionFailLeadsToException()
 {
     $connection = new Connection('tcp://0.0.0.1:15');
     try {
         $connection->connect();
         $this->fail('Expected an exception!');
     } catch (ConnectionException $ex) {
         $this->assertContains('Could not connect to a broker', $ex->getMessage());
         $this->assertInstanceOf('Stomp\\Exception\\ConnectionException', $ex->getPrevious(), 'There should be a previous exception.');
         /** @var ConnectionException $prev */
         $prev = $ex->getPrevious();
         $hostInfo = $prev->getConnectionInfo();
         $this->assertEquals('0.0.0.1', $hostInfo['host']);
         $this->assertEquals('15', $hostInfo['port']);
     }
 }
 /**
  * @expectedException \Stomp\Exception\StompException
  */
 public function testWriteFrameThrowsExceptionIfNotConnected()
 {
     $connection = new Connection('tcp://localhost');
     $connection->writeFrame(new Frame());
 }