From 9bb6d2bb0af7bf9ae8af65ef7d9c35d5f02bfc87 Mon Sep 17 00:00:00 2001 From: Dinosaur Date: Thu, 7 Feb 2019 13:39:01 +0700 Subject: [PATCH 1/5] Create clientInfo.cs --- Assignments/HW1/DNWS/clientInfo.cs | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Assignments/HW1/DNWS/clientInfo.cs diff --git a/Assignments/HW1/DNWS/clientInfo.cs b/Assignments/HW1/DNWS/clientInfo.cs new file mode 100644 index 0000000..aec7606 --- /dev/null +++ b/Assignments/HW1/DNWS/clientInfo.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace DNWS +{ + class StatPlugin : IPlugin + { + protected static Dictionary statDictionary = null; + public StatPlugin() + { + if (statDictionary == null) + { + statDictionary = new Dictionary(); + + } + } + + public void PreProcessing(HTTPRequest request) + { + if (statDictionary.ContainsKey(request.Url)) + { + statDictionary[request.Url] = (int)statDictionary[request.Url] + 1; + } + else + { + statDictionary[request.Url] = 1; + } + } + public HTTPResponse GetResponse(HTTPRequest request) + { + HTTPResponse response = null; + StringBuilder sb = new StringBuilder(); + sb.Append("

Stat:

"); + foreach (KeyValuePair entry in statDictionary) + { + sb.Append(entry.Key + ": " + entry.Value.ToString() + "
"); + } + sb.Append(""); + response = new HTTPResponse(200); + response.body = Encoding.UTF8.GetBytes(sb.ToString()); + return response; + } + + public HTTPResponse PostProcessing(HTTPResponse response) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file From 32cd5fa7297217118d75c1c36562f50f8ebda892 Mon Sep 17 00:00:00 2001 From: Dinosaur Date: Thu, 7 Feb 2019 13:57:33 +0700 Subject: [PATCH 2/5] add file clientInfo.cs and fixed config.json --- Assignments/HW1/DNWS/config.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Assignments/HW1/DNWS/config.json b/Assignments/HW1/DNWS/config.json index 168ce81..3057099 100644 --- a/Assignments/HW1/DNWS/config.json +++ b/Assignments/HW1/DNWS/config.json @@ -14,6 +14,12 @@ "Class" : "DNWS.OXPlugin", "Preprocessing" : "false", "Postprocessing" :"false" + }, + { + "Path" : "client", + "Class" : "DNWS.clientInfo", + "Preprocessing" : "false", + "Postprocessing" :"false" } ] } \ No newline at end of file From 52bd69f6668dd86bb14cf3f8d829c4c8d8345953 Mon Sep 17 00:00:00 2001 From: Dinosaur Date: Thu, 7 Feb 2019 14:01:52 +0700 Subject: [PATCH 3/5] add file client.cs and fixed config.json --- Assignments/HW1/DNWS/client.cs | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Assignments/HW1/DNWS/client.cs diff --git a/Assignments/HW1/DNWS/client.cs b/Assignments/HW1/DNWS/client.cs new file mode 100644 index 0000000..e81933e --- /dev/null +++ b/Assignments/HW1/DNWS/client.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace DNWS +{ + class client : IPlugin + { + protected static Dictionary statDictionary = null; + public client() + { + if (statDictionary == null) + { + statDictionary = new Dictionary(); + + } + } + + public void PreProcessing(HTTPRequest request) + { + if (statDictionary.ContainsKey(request.Url)) + { + statDictionary[request.Url] = (int)statDictionary[request.Url] + 1; + } + else + { + statDictionary[request.Url] = 1; + } + } + public HTTPResponse GetResponse(HTTPRequest request) + { + request.getPropertyByKey("RemoteEndPoint"); + string _req = request.req; + HTTPResponse response = null; + StringBuilder sb = new StringBuilder(); + string[] arr = _req.Split("User-Agent:"); + string[] arr2 = arr[1].Split("Accept"); + string[] arr3 = _req.Split("Accept-Encoding:"); + string[] arr4 = arr3[1].Split("Accept"); + string[] arr5 = _req.Split("Accept-Language:"); + string[] port1 = request.getPropertyByKey("RemoteEndPoint").Split(":"); + string[] port = request.getPropertyByKey("RemoteEndPoint").Split(":"); + // string[] arr3 = _req. + + sb.Append("

Client IP : " +port[0] + "

"); + sb.Append("

Port : " + port[1] + "

"); + + + sb.Append("

Browser information : "+ arr2[0] +"

"); + foreach (KeyValuePair entry in statDictionary) + { + sb.Append(entry.Key + ": " + entry.Value.ToString() + "
"); + } + + + + sb.Append("

Accept-Language : " + arr5[1] + "


"); + + sb.Append("

Accept-Encoding : " + arr4[0] + "


"); + + + sb.Append(""); + + response = new HTTPResponse(200); + response.body = Encoding.UTF8.GetBytes(sb.ToString()); + return response; + } + + public HTTPResponse PostProcessing(HTTPResponse response) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file From 394cb74de49edf7207e1636be6e868c53f6caec1 Mon Sep 17 00:00:00 2001 From: Dinosaur Date: Thu, 28 Feb 2019 22:23:15 +0700 Subject: [PATCH 4/5] HW2 fin --- .gitignore | 1 + Assignments/HW1/DNWS/clientInfo.cs | 50 ------------------------------ 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 Assignments/HW1/DNWS/clientInfo.cs diff --git a/.gitignore b/.gitignore index 1d74e21..d09c98c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .vscode/ +Assignments/HW1/DNWS/clientInfo.cs diff --git a/Assignments/HW1/DNWS/clientInfo.cs b/Assignments/HW1/DNWS/clientInfo.cs deleted file mode 100644 index aec7606..0000000 --- a/Assignments/HW1/DNWS/clientInfo.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace DNWS -{ - class StatPlugin : IPlugin - { - protected static Dictionary statDictionary = null; - public StatPlugin() - { - if (statDictionary == null) - { - statDictionary = new Dictionary(); - - } - } - - public void PreProcessing(HTTPRequest request) - { - if (statDictionary.ContainsKey(request.Url)) - { - statDictionary[request.Url] = (int)statDictionary[request.Url] + 1; - } - else - { - statDictionary[request.Url] = 1; - } - } - public HTTPResponse GetResponse(HTTPRequest request) - { - HTTPResponse response = null; - StringBuilder sb = new StringBuilder(); - sb.Append("

Stat:

"); - foreach (KeyValuePair entry in statDictionary) - { - sb.Append(entry.Key + ": " + entry.Value.ToString() + "
"); - } - sb.Append(""); - response = new HTTPResponse(200); - response.body = Encoding.UTF8.GetBytes(sb.ToString()); - return response; - } - - public HTTPResponse PostProcessing(HTTPResponse response) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file From 6d4470fe13af0d9c2ee1be85017a3ea864897a30 Mon Sep 17 00:00:00 2001 From: Dinosaur Date: Thu, 28 Feb 2019 22:26:30 +0700 Subject: [PATCH 5/5] HW2 fin --- Assignments/HW1/DNWS/Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Assignments/HW1/DNWS/Program.cs b/Assignments/HW1/DNWS/Program.cs index 89a259a..f05018e 100644 --- a/Assignments/HW1/DNWS/Program.cs +++ b/Assignments/HW1/DNWS/Program.cs @@ -5,6 +5,7 @@ using System.Net; using System.IO; using Microsoft.Extensions.Configuration; +using System.Threading; namespace DNWS { @@ -287,8 +288,11 @@ public void Start() // Get one, show some info _parent.Log("Client accepted:" + clientSocket.RemoteEndPoint.ToString()); HTTPProcessor hp = new HTTPProcessor(clientSocket, _parent); + Thread thread = new Thread(new ThreadStart(hp.Process)); //// + thread.Start(); ///// + // Single thread - hp.Process(); + //hp.Process(); // End single therad }