我正在从js到我的PHP服务器执行wss请求并且握手工作正常,但响应数据帧的第一个字节为C7而不是81,因此我无法解码数据。
我正在使用受信任的SSL证书。
我的PHP代码是:
创建websoket服务器:
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert', '../../engine/fscert.pem');
stream_context_set_option($context, 'ssl', 'local_pk', '../../engine/fskey.key');
stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
stream_context_set_option($context, 'ssl', 'verify_peer', false);
$errno, $errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
$socket = stream_socket_server("tls://my-server.com:9444", $errno, $errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
握手功能:
$SecWebSocketAccept = base64_encode(pack('H*', sha1($info['Sec-WebSocket-Key'] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
$upgrade = "HTTPS/1.1 101 Web Socket Protocol Handshake\r\n" .
"Upgrade: websocket\r\n" .
"Connection: Upgrade\r\n" .
"Sec-WebSocket-Accept:$SecWebSocketAccept\r\n\r\n";
fwrite($connect, $upgrade);
我哪里错了?