芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/joolsmen.com/chat/vendor/ratchet/rfc6455/tests/ab/startServer.php
on('connection', function (React\Socket\ConnectionInterface $connection) use ($negotiator, $closeFrameChecker, $uException) { $headerComplete = false; $buffer = ''; $parser = null; $connection->on('data', function ($data) use ($connection, &$parser, &$headerComplete, &$buffer, $negotiator, $closeFrameChecker, $uException) { if ($headerComplete) { $parser->onData($data); return; } $buffer .= $data; $parts = explode("\r\n\r\n", $buffer); if (count($parts) < 2) { return; } $headerComplete = true; $psrRequest = \GuzzleHttp\Psr7\parse_request($parts[0] . "\r\n\r\n"); $negotiatorResponse = $negotiator->handshake($psrRequest); $negotiatorResponse = $negotiatorResponse->withAddedHeader("Content-Length", "0"); $connection->write(\GuzzleHttp\Psr7\str($negotiatorResponse)); if ($negotiatorResponse->getStatusCode() !== 101) { $connection->end(); return; } $parser = new \Ratchet\RFC6455\Messaging\MessageBuffer($closeFrameChecker, function (MessageInterface $message) use ($connection) { $connection->write($message->getContents()); }, function (FrameInterface $frame) use ($connection, &$parser) { switch ($frame->getOpCode()) { case Frame::OP_CLOSE: $connection->end($frame->getContents()); break; case Frame::OP_PING: $connection->write($parser->newFrame($frame->getPayload(), true, Frame::OP_PONG)->getContents()); break; } }, true, function () use ($uException) { return $uException; }); array_shift($parts); $parser->onData(implode("\r\n\r\n", $parts)); }); }); $loop->run();