diff --git a/README.md b/README.md index e4f0287..8153661 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ class Chat implements SocketObserver { public function onClose(SocketInterface $conn) { $this->_clients->detach($conn); } + + public function onError(SocketInterface $conn, \Exception $e) { + return $this->_factory->newCommand('CloseConnection', $conn); + } } // Run the server application through the WebSocket protocol diff --git a/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php b/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php index d701c39..4e3eb48 100644 --- a/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php +++ b/lib/Ratchet/Protocol/WebSocket/Version/HyBi10.php @@ -96,12 +96,25 @@ class HyBi10 implements VersionInterface { } if($payloadLength === 126) { + $msg_len = bindec(sprintf('%08b', ord($data[2])) . sprintf('%08b', ord($data[3]))); $mask = substr($data, 4, 4); $payloadOffset = 8; } elseif($payloadLength === 127) { + $msg_len = bindec( + sprintf('%08b', ord($data[2])) + . sprintf('%08b', ord($data[3])) + . sprintf('%08b', ord($data[4])) + . sprintf('%08b', ord($data[5])) + . sprintf('%08b', ord($data[6])) + . sprintf('%08b', ord($data[7])) + . sprintf('%08b', ord($data[8])) + . sprintf('%08b', ord($data[9])) + ); + $mask = substr($data, 10, 4); $payloadOffset = 14; } else { + $msg_len = $payloadLength; $mask = substr($data, 2, 4); $payloadOffset = 6; } diff --git a/lib/Ratchet/Server.php b/lib/Ratchet/Server.php index 5934638..02ad04f 100644 --- a/lib/Ratchet/Server.php +++ b/lib/Ratchet/Server.php @@ -105,11 +105,14 @@ class Server implements SocketObserver, \IteratorAggregate { // This idea works* but... // 1) A single DDOS attack will block the entire application (I think) // 2) What if the last message in the frame is equal to $recv_bytes? Would loop until another msg is sent + // 3) This failed...an intermediary can set their buffer lower and this still propagates a fragment // Need to 1) proc_open the recv() calls. 2) ??? +/* while ($bytes === $recv_bytes) { $bytes = $conn->recv($buf, $recv_bytes, 0); $data .= $buf; } +*/ $res = $this->onRecv($conn, $data); } else {