【文件属性】:
文件名称:c# WebSocket服务端握手解包原理
文件大小:28KB
文件格式:ZIP
更新时间:2021-04-29 04:24:31
WebSocket
///
/// 生成Sec-WebSocket-Accept
///
/// 客户端握手信息
/// Sec-WebSocket-Accept
private static string GetSecKeyAccetp(byte[] handShakeBytes, int bytesLength)
{
string handShakeText = Encoding.UTF8.GetString(handShakeBytes, 0, bytesLength);
string key = string.Empty;
Regex r = new Regex(@"Sec\-WebSocket\-Key:(.*?)\r\n");
Match m = r.Match(handShakeText);
if (m.Groups.Count != 0)
{
key = Regex.Replace(m.Value, @"Sec\-WebSocket\-Key:(.*?)\r\n", "$1").Trim();
}
byte[] encryptionString = SHA1.Create().ComputeHash(Encoding.ASCII.GetBytes(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
return Convert.ToBase64String(encryptionString);
}
【文件预览】:
WebSocketServer
----bin()
--------Debug()
----Program.cs(7KB)
----obj()
--------x86()
----WebSocketServer.csproj(2KB)
----Properties()
--------AssemblyInfo.cs(1KB)
websocketclient.html