rfc6455/Version/RFC6455/Connection.php
Chris Boden 491919f7dc [WebSocket] Connection API
All implementations of ConnectionInterface return themselves
2012-07-22 20:05:04 -04:00

33 lines
778 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());
return $this;
}
/**
* {@inheritdoc}
*/
public function close($code = 1000) {
if ($code instanceof DataInterface) {
$this->send($code);
} else {
$this->send(new Frame(pack('n', $code), true, Frame::OP_CLOSE));
}
$this->getConnection()->close();
}
}