コード例 #1
0
ファイル: Connection.php プロジェクト: netconstructor/Ratchet
 public function send($msg)
 {
     if (!$msg instanceof DataInterface) {
         $msg = new Frame($msg);
     }
     $this->getConnection()->send($msg->getContents());
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: dizard/Ratchet
 /**
  * {@inheritdoc}
  */
 public function sendBinary($msg)
 {
     if (!$this->WebSocket->closing) {
         if (!$msg instanceof DataInterface) {
             $msg = new Frame($msg, true, Frame::OP_BINARY);
         }
         $this->getConnection()->send($msg->getContents());
     }
     return $this;
 }
コード例 #3
0
ファイル: WebSocket.php プロジェクト: pacho104/redbpim
 public function close($code = 1000)
 {
     $frame = new Frame(pack('n', $code), true, Frame::OP_CLOSE);
     $this->_stream->write($frame->getContents());
     $this->_stream->end();
 }
コード例 #4
0
ファイル: Connection.php プロジェクト: khelle/surume
 /**
  * @override
  */
 public function send($msg)
 {
     if (!$this->WebSocket->closing) {
         if (!$msg instanceof DataInterface) {
             $msg = new Frame($msg);
         }
         $this->connection->send($msg->getContents());
     }
     return $this;
 }
コード例 #5
0
 /**
  * @param $data
  * @param string $type
  * @param bool $masked
  */
 public function sendData($data, $type = 'text', $masked = true)
 {
     if (!$this->isConnected()) {
         $this->disconnect();
         return;
     }
     $msg = new Frame(json_encode($data));
     $this->getSocket()->write($msg->getContents());
 }
コード例 #6
0
ファイル: FrameTest.php プロジェクト: netconstructor/Ratchet
 public function testExtractOverflow()
 {
     $string1 = $this->generateRandomString();
     $frame1 = Frame::create($string1);
     $string2 = $this->generateRandomString();
     $frame2 = Frame::create($string2);
     $cat = new Frame();
     $cat->addBuffer($frame1->getContents() . $frame2->getContents());
     $this->assertEquals($frame1->getContents(), $cat->getContents());
     $this->assertEquals($string1, $cat->getPayload());
     $uncat = new Frame();
     $uncat->addBuffer($cat->extractOverflow());
     $this->assertEquals($string1, $cat->getPayload());
     $this->assertEquals($string2, $uncat->getPayload());
 }
コード例 #7
0
ファイル: FrameTest.php プロジェクト: perfect-coin/chat
 /**
  * @covers Ratchet\WebSocket\Version\RFC6455\Frame::getContents
  */
 public function testGetContents()
 {
     $msg = 'The quick brown fox jumps over the lazy dog.';
     $frame1 = new Frame($msg);
     $frame2 = new Frame($msg);
     $frame2->maskPayload();
     $this->assertNotEquals($frame1->getContents(), $frame2->getContents());
     $this->assertEquals(strlen($frame1->getContents()) + 4, strlen($frame2->getContents()));
 }