private bool IsValidHandshake(byte[] buffer, int size) { // parse the client handshake and generate a response handshake var handshakeString = Encoding.ASCII.GetString(buffer, 0, size); ClientHandshake = new ClientHandshake(handshakeString); // check if the information in the client handshake is valid // TODO 404 on invalid location and 403 on invalid origin if (ClientHandshake.IsValid() && "ws://" + ClientHandshake.Host == Location && ClientHandshake.Origin == Origin) { return(true); } else { return(false); } }
/// <summary> /// Create a new web socket connection /// </summary> /// <param name="socket">the connecting socket</param> /// <param name="handshake">the handshake sent upon connecting</param> public WebSocketConnection(Socket socket, ClientHandshake handshake) { Socket = socket; Handshake = handshake; }