private ServerHandshake GenerateResponseHandshake() { var acceptString = CalculateAcceptString(ClientHandshake.Key); var responseHandshake = new ServerHandshake() { Accept = acceptString, Location = "ws://" + ClientHandshake.Host + ClientHandshake.ResourceName.ToString(), Origin = ClientHandshake.Origin, SubProtocol = ClientHandshake.SubProtocol, }; return(responseHandshake); }
private void BeginSendServerHandshake(ServerHandshake handshake, Socket socket) { var stringShake = "HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Accept: " + handshake.Accept + "\r\n"; if (!string.IsNullOrEmpty(handshake.SubProtocol)) { stringShake += "Sec-WebSocket-Protocol: " + handshake.SubProtocol + "\r\n"; } stringShake += "\r\n"; // generate a byte array representation of the handshake byte[] byteResponse = Encoding.ASCII.GetBytes(stringShake); socket.AsyncSend(byteResponse, (size) => { if (_onSuccess != null) { _onSuccess(ClientHandshake); } }); }