Esempio n. 1
0
        private static void HandleRequests(HttpListener listener)
        {
            Task <HttpListenerContext> contextTask = listener.GetContextAsync();

            HttpListenerContext context = contextTask.Result;
            HttpListenerRequest request = context.Request;
            StreamReader        reader  = new StreamReader(request.InputStream);
            string s = reader.ReadToEnd();

            s = StringUtil.Decrypt(s);
            reader.Close();


            Message RecievedMessage = MsgOpsJson.DeSerialize(s);

            Console.WriteLine($"{RecievedMessage.Sender}: {RecievedMessage.Data}");

            HttpListenerResponse response = context.Response;
            Response             authRes  = new Response()
            {
                Status = true
            };
            string responseStr = JsonConvert.SerializeObject(authRes);

            responseStr = StringUtil.Crypt(responseStr);
            using (StreamWriter output = new StreamWriter(response.OutputStream))
            {
                output.Write(responseStr);
            }
        }
Esempio n. 2
0
        public static void SendMessage(Message msg)
        {
            string json = MsgOpsJson.Serialize(msg);

            json = StringUtil.Crypt(json);
            HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");

            client.PostAsync(uri, content);
        }
Esempio n. 3
0
        public static async Task <bool> GetIn(Message msg)
        {
            string json = MsgOpsJson.Serialize(msg);

            json = StringUtil.Crypt(json);
            HttpContent         content  = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(uri, content);

            string responseString = await response.Content.ReadAsStringAsync();

            responseString = StringUtil.Decrypt(responseString);
            Response _Response = JsonConvert.DeserializeObject <Response>(responseString);
            bool     Success   = _Response.Status;

            return(Success);
        }