本文整理汇总了PHP中Protocol::route方法的典型用法代码示例。如果您正苦于以下问题:PHP Protocol::route方法的具体用法?PHP Protocol::route怎么用?PHP Protocol::route使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::route方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: route
public function route($event, Message $request, Message $response = null)
{
if ($this->upgraded) {
switch ($request->getOpCode()) {
case Request::OPCODE_CTRL_CLOSE:
$this->sendClose($request);
break;
case Request::OPCODE_CTRL_PING:
$this->sendPong($request);
break;
case Request::OPCODE_CTRL_PONG:
break;
case Request::OPCODE_NCTRL_TEXT:
case Request::OPCODE_NCTRL_BIN:
parent::route($event, $request, new Response());
break;
default:
throw new \Exception("Unknown opcode " . var_export($request->getOpCode(), 1));
}
} else {
$response = new \Phasty\Server\Http\Response();
$response->setWriteStream($request->getReadStream());
$hash = $this->getAcceptHash($request->getHeader("Sec-WebSocket-Key")[0]);
$origin = $request->getHeader("Origin")[0];
$location = "ws://" . $request->getHeader("Host")[0] . $request->getPath();
$response->setCode(101)->setHeader("Upgrade", "websocket")->setHeader("Connection", "Upgrade")->setHeader("Origin", $origin)->setHeader("Sec-WebSocket-Accept", $hash);
if ($request->hasHeader("Sec-WebSocket-Protocol")) {
$request->setHeader("Sec-WebSocket-Protocol", "chat");
}
$response->on("sent", function () use($request) {
$this->upgraded = true;
$request->trigger("dispatched", ["nextProtocol" => $this]);
})->send();
}
}