有谁用过swoole 的 onHandShake()时间来做socket 连接加密 ? 我现在用workerman 没有找到这个
我现在需要做这个
$server->on('handshake', function (\swoole_http_request $request, \swoole_http_response $response) {
// print_r( $request->header );
// if (如果不满足我某些自定义的需求条件,那么返回end输出,返回false,握手失败) {
// $response->end();
// return false;
// }
// websocket握手连接算法验证
$secWebSocketKey = $request->header;
$patten = '#^{21}==$#';
if (0 === preg_match($patten, $secWebSocketKey) || 16 !== strlen(base64_decode($secWebSocketKey))) {
$response->end();
return false;
}
echo $request->header;
$key = base64_encode(sha1(
$request->header . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
true
));
$headers = ;
// WebSocket connection to 'ws://127.0.0.1:9502/'
// failed: Error during WebSocket handshake:
// Response must not include 'Sec-WebSocket-Protocol' header if not present in request: websocket
if (isset($request->header)) {
$headers = $request->header;
}
foreach ($headers as $key => $val) {
$response->header($key, $val);
}
$response->status(101);
$response->end();
echo "connected!" . PHP_EOL;
return true;
});
好像有个onWebSocketConnect方法
嗯嗯 我想在连接socket 的时候卡住他 不让非我网站的连接