diff --git a/src/Ratchet/WebSocket/Version/RFC6455.php b/src/Ratchet/WebSocket/Version/RFC6455.php index 21841cd..de21e78 100644 --- a/src/Ratchet/WebSocket/Version/RFC6455.php +++ b/src/Ratchet/WebSocket/Version/RFC6455.php @@ -93,27 +93,19 @@ class RFC6455 implements VersionInterface { $frame = $from->WebSocket->frame; if (!$frame->isMasked()) { - unset($from->WebSocket->frame); - - $from->send($this->newFrame($frame::CLOSE_PROTOCOL, true, $frame::OP_CLOSE)); - $from->getConnection()->close(); - - return; + return $from->close($frame::CLOSE_PROTOCOL); } $opcode = $frame->getOpcode(); if ($opcode > 2) { + if ($frame->getPayloadLength() > 125) { + return $from->close($frame::CLOSE_PROTOCOL); + } + switch ($opcode) { case $frame::OP_CLOSE: - $from->close($frame->getPayload()); -/* - $from->send($frame->unMaskPayload()); - $from->getConnection()->close(); -*/ -// $from->send(Frame::create(Frame::CLOSE_NORMAL, true, Frame::OP_CLOSE)); - - return; + return $from->close($frame); break; case $frame::OP_PING: $from->send($this->newFrame($frame->getPayload(), true, $frame::OP_PONG)); diff --git a/src/Ratchet/WebSocket/Version/RFC6455/Connection.php b/src/Ratchet/WebSocket/Version/RFC6455/Connection.php index 88b0707..c1c3f7c 100644 --- a/src/Ratchet/WebSocket/Version/RFC6455/Connection.php +++ b/src/Ratchet/WebSocket/Version/RFC6455/Connection.php @@ -20,7 +20,11 @@ class Connection extends AbstractConnectionDecorator { * {@inheritdoc} */ public function close($code = 1000) { - $this->send(new Frame($code, true, Frame::OP_CLOSE)); + if ($code instanceof DataInterface) { + $this->send($code); + } else { + $this->send(new Frame(Frame::encode(sprintf('%016b', $code)), true, Frame::OP_CLOSE)); + } $this->getConnection()->close(); }