/// <summary> /// Constantly listening to client request and respond to it accordingly /// </summary> /// <param name="sr"></param> /// <param name="sw"></param> private async void ListeningToClient(StreamReader sr, StreamWriter sw) { while (true) { Request req; Response res; if (!auth_bypass) { string encryptedSerializedReq = await sr.ReadLineAsync(); Console.WriteLine("[Encrypted Request]"); byte[] serializedReq = EncryptionAES.Decrypt(encryptedSerializedReq, masterKey, iv); req = (Request)Serialization.DeserializeData(serializedReq); } else { req = (Request)Serialization.DeserializeObject(await sr.ReadLineAsync()); Console.WriteLine("[Unencrypted Request]"); } //Redirect r = new Redirect(); res = Redirect.redirection(req); /* * To get object Data from request * <Class> objData = (<Class>)req.Data; * * Process the request Data * TODO: Process (Symmetric Encryption and decryption) and retrieve/insert Data * * Create a reponse obj * Response res = new Response() * { * Data = <object>, * Flag = <Flag>, * Reason = <Include Reason if necessary> * Sucess = <true/false> * } */ //LoginAccount acc = (LoginAccount)req.Data; //Console.WriteLine("password input: " + acc.password); //Constants c = new Constants(); //res = new Response() //{ // Data = new House() // { // Address = "Blk 912, Hougang Street 91, #07-42", // Country = "Singapore", // PostalCode = "S530912" // }, // Flag = 1, // Reason = "SENDING BACK", // Success = true //}; if (!auth_bypass) { Console.WriteLine("[Encrypted Response]"); byte[] seralizedRes = Serialization.SerializeData(res); string encryptedSerializedRes = EncryptionAES.Encrypt(seralizedRes, masterKey, iv); await sw.WriteLineAsync(encryptedSerializedRes); } else { Console.WriteLine("[Unencrypted Response]"); await sw.WriteLineAsync(Serialization.SerializeObject(res)); } sw.Flush(); Console.WriteLine("[Sending Response]"); } }