public function send($msg) { if (!$msg instanceof DataInterface) { $msg = new Frame($msg); } $this->getConnection()->send($msg->getContents()); }
/** * {@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; }
public function close($code = 1000) { $frame = new Frame(pack('n', $code), true, Frame::OP_CLOSE); $this->_stream->write($frame->getContents()); $this->_stream->end(); }
/** * @override */ public function send($msg) { if (!$this->WebSocket->closing) { if (!$msg instanceof DataInterface) { $msg = new Frame($msg); } $this->connection->send($msg->getContents()); } return $this; }
/** * @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()); }
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()); }
/** * @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())); }