コード例 #1
0
 /**
  * Parses WebSocket frames out of a raw data stream
  *
  * Any numbe of frames may be parsed. If the data chunk contains no
  * complete frames, no frames may be returned. The frame parses maintains
  * its state so subsequent data reads can be passed to this method to
  * complete partial frames.
  *
  * @param string $data the raw data.
  *
  * @return array an array of parsed {@link Net_Notifier_WebSocket_Frame}
  *               objects.
  */
 public function parse($data)
 {
     $frames = array();
     while ($data != '') {
         $data = $this->currentFrame->parse($data);
         if ($data != '') {
             $frames[] = $this->currentFrame;
             $this->currentFrame = new Net_Notifier_WebSocket_Frame();
         }
     }
     // if we received exactly enough data, the last frame is also complete
     $state = $this->currentFrame->getState();
     if ($state === Net_Notifier_WebSocket_Frame::STATE_DONE) {
         $frames[] = $this->currentFrame;
         $this->currentFrame = new Net_Notifier_WebSocket_Frame();
     }
     return $frames;
 }
コード例 #2
0
 /**
  * Sends a pong frame
  *
  * Pongs are sent automatically in response to pings. They can be sent
  * manually with this method.
  *
  * @param string $message the message to include with the pong frame.
  *
  * @return void
  */
 public function pong($message)
 {
     $frame = new Net_Notifier_WebSocket_Frame($message, Net_Notifier_WebSocket_Frame::TYPE_PONG);
     $this->send($frame->__toString());
 }