+ // TODO: verify both variables
+ // here there is a change of the socket status from start to handshaked
+ // th headers are saved too but without any further access so we skip it
+
+
+
+ $inno = 'x3JJHMbDL1EzLkh9GBhXDw==';
+ $outo = sha1($inno . $this->magicGUID);
+ $rawToken = "";
+ for ($i = 0; $i < 20; $i++) {
+ $rawToken .= chr(hexdec(substr($outo,$i*2, 2)));
+ }
+
+ $outo = base64_encode($rawToken);
+
+ $webSocketKeyHash = sha1($headers['Sec-Websocket-Key'] . $this->magicGUID);
+ $rawToken = "";
+ for ($i = 0; $i < 20; $i++) {
+ $rawToken .= chr(hexdec(substr($webSocketKeyHash,$i*2, 2)));
+ }
+ $handshakeToken = base64_encode($rawToken);
+ $subProtocol = (isset($headers['Sec-Websocket-Protocol'])) ?
+ $this->processProtocol($headers['Sec-Websocket-Protocol']) : "";
+ $extensions = (isset($headers['Sec-Websocket-Extensions'])) ?
+ $this->processExtensions($headers['Sec-Websocket-Extensions']) : "";
+
+ $headers_out['HTTP-Response'] = "101 Switching Protocols";
+ $headers_out['Upgrade'] = 'websocket';
+ $headers_out['Connection'] = 'Upgrade';
+ $headers_out['Sec-WebSocket-Accept'] = "$handshakeToken$subProtocol$extensions";
+
+ return ("");
+ }
+
+ static function close()
+ {
+ return(chr(0x88).chr(0x02).chr(0xe8).chr(0x03));