public static bool CheckHandshake(Context AContext) { if (AContext.ReceivedByteCount > 8) { ClientHandshake AHandshake = new ClientHandshake(new ArraySegment <byte>(AContext.Buffer, AContext.ReceivedByteCount - 8, 8), AContext.Header); // See if our header had the required information if (AHandshake.IsValid()) { // Optionally check Origin and Location if they're set. if (Origin != string.Empty) { if (AHandshake.Origin != "http://" + Origin) { return(false); } } if (Location != string.Empty) { if (AHandshake.Host != Location + ":" + AContext.Server.Port.ToString()) { return(false); } } // Generate response handshake for the client ServerHandshake ServerShake = GenerateResponseHandshake(AHandshake); // Send the response handshake SendServerHandshake(ServerShake, AContext); return(true); } } return(false); }
private static ServerHandshake GenerateResponseHandshake(ClientHandshake AHandshake) { ServerHandshake AResponseHandshake = new ServerHandshake(); AResponseHandshake.Location = "ws://" + AHandshake.Host + AHandshake.ResourcePath; AResponseHandshake.Origin = AHandshake.Origin; AResponseHandshake.SubProtocol = AHandshake.SubProtocol; AResponseHandshake.AnswerBytes = GenerateAnswerBytes(AHandshake.Key1, AHandshake.Key2, AHandshake.ChallengeBytes); return(AResponseHandshake); }
public static bool CheckHandshake(Context AContext) { if(AContext.ReceivedByteCount > 8) { ClientHandshake AHandshake = new ClientHandshake(new ArraySegment<byte>(AContext.Buffer, AContext.ReceivedByteCount-8, 8), AContext.Header); // See if our header had the required information if (AHandshake.IsValid()) { // Optionally check Origin and Location if they're set. if (Origin != string.Empty) if (AHandshake.Origin != "http://" + Origin) return false; if (Location != string.Empty) if (AHandshake.Host != Location + ":" + AContext.Server.Port.ToString()) return false; // Generate response handshake for the client ServerHandshake ServerShake = GenerateResponseHandshake(AHandshake); // Send the response handshake SendServerHandshake(ServerShake, AContext); return true; } } return false; }
private static ServerHandshake GenerateResponseHandshake(ClientHandshake AHandshake) { ServerHandshake AResponseHandshake = new ServerHandshake(); AResponseHandshake.Location = "ws://" + AHandshake.Host + AHandshake.ResourcePath; AResponseHandshake.Origin = AHandshake.Origin; AResponseHandshake.SubProtocol = AHandshake.SubProtocol; AResponseHandshake.AnswerBytes = GenerateAnswerBytes(AHandshake.Key1, AHandshake.Key2, AHandshake.ChallengeBytes); return AResponseHandshake; }