rfc6455/Version/RFC6455/Connection.php
Chris Boden 653d8fb482 [WebSocket] RFC Protocol Compliance
Refs #13
Fixed AB tests: 2.5, 4.*
RFC fails connections on bad control frames
2012-06-16 11:49:46 -04:00

31 lines
777 B
PHP

<?php
namespace Ratchet\WebSocket\Version\RFC6455;
use Ratchet\ConnectionInterface;
use Ratchet\AbstractConnectionDecorator;
use Ratchet\WebSocket\Version\DataInterface;
/**
* {@inheritdoc}
*/
class Connection extends AbstractConnectionDecorator {
public function send($msg) {
if (!($msg instanceof DataInterface)) {
$msg = new Frame($msg);
}
$this->getConnection()->send($msg->getContents());
}
/**
* {@inheritdoc}
*/
public function close($code = 1000) {
if ($code instanceof DataInterface) {
$this->send($code);
} else {
$this->send(new Frame(Frame::encode(sprintf('%016b', $code)), true, Frame::OP_CLOSE));
}
$this->getConnection()->close();
}
}