void ProcessWebsocketConnect(NetworkStream stream)
{
byte[] temp = new byte[4096];
temp[0] = 71;
int read = stream.Read(temp, 1, (int)temp.Length - 1);
MemoryStream memstream = new MemoryStream(temp);
StreamReader reader = new StreamReader(memstream);
var headers = new Dictionary<string, string>();
string line = reader.ReadLine();
while( !string.IsNullOrEmpty(line) )
{
var tokens = line.Split(new char[] { ':' }, 2);
if (!string.IsNullOrWhiteSpace(line) && tokens.Length > 1)
{
headers[tokens[0]] = tokens[1].Trim();
}
line = reader.ReadLine();
}
String secWebSocketAccept = ComputeWebSocketHandshakeSecurityHash09(headers["Sec-WebSocket-Key"]);
// send handshake to this client only
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake");
writer.WriteLine("Upgrade: WebSocket");
writer.WriteLine("Connection: Upgrade");
writer.WriteLine("Sec-WebSocket-Accept: " + secWebSocketAccept);
writer.WriteLine("");
writer.Flush();
}