Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

600611022 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .vs/261433/v15/.suo
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
9 changes: 9 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ExpandedNodes": [
"",
"\\Assignments",
"\\Assignments\\HW1",
"\\Assignments\\HW1\\DNWS"
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
16 changes: 10 additions & 6 deletions Assignments/HW1/DNWS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.IO;
using Microsoft.Extensions.Configuration;

using System.Threading;

namespace DNWS
{
// Main class
Expand Down Expand Up @@ -33,7 +35,8 @@ public void Start()
static void Main(string[] args)
{
Program p = new Program();
p.Start();
Thread thread= new Thread(new ThreadStart(p.Start));
thread.Start();
}
}

Expand Down Expand Up @@ -150,7 +153,7 @@ protected HTTPResponse getFile(String path)
/// <summary>
/// Get a request from client, process it, then return response to client
/// </summary>
public void Process()
public void Process(object state) //1039 idea
{
NetworkStream ns = new NetworkStream(_client);
string requestStr = "";
Expand Down Expand Up @@ -281,15 +284,16 @@ public void Start()
while (true)
{
try
{
{//1039 teah me
// Wait for client
clientSocket = serverSocket.Accept();
// Get one, show some info
_parent.Log("Client accepted:" + clientSocket.RemoteEndPoint.ToString());
HTTPProcessor hp = new HTTPProcessor(clientSocket, _parent);
// Single thread
hp.Process();
// End single therad
ThreadPool.SetMaxThreads(100, 0); //set max values of ThreadPool.
ThreadPool.SetMinThreads(1, 0); //set min values of ThreadPool.
ThreadPool.QueueUserWorkItem(new WaitCallback(hp.Process)); // Queue the task.


}
catch (Exception ex)
Expand Down
37 changes: 37 additions & 0 deletions Assignments/HW1/DNWS/clintinfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace DNWS
{
class clintinfo : IPlugin
{
public void PreProcessing(HTTPRequest request)
{
throw new NotImplementedException();
}
public HTTPResponse GetResponse(HTTPRequest request)
{
HTTPResponse response = null; //600611024 and 600611030 give me an idea and teach me
StringBuilder sb = new StringBuilder();
string[] getter = request.getPropertyByKey("RemoteEndPoint").Split(':');
sb.Append("<html><body>Client IP: " + getter[0] + "</br></br>");
sb.Append("Client Port: " + getter[1] + "</br></br>");
sb.Append("Browser Information: " + request.getPropertyByKey("User-Agent") + "</br></br>");
sb.Append("Accept-Language: " + request.getPropertyByKey("Accept-Language") + "</br></br>");
sb.Append("Accept-Encoding: " + request.getPropertyByKey("Accept-Encoding")); //600611039 help me for this
sb.Append("</br>Threads-count: " + Process.GetCurrentProcess().Threads.Count);
sb.Append("<br>Threads State : " + Thread.CurrentThread.ThreadState);
sb.Append("<br>Threads ID : " + Thread.CurrentThread.ManagedThreadId);
sb.Append("</body></html>");
response = new HTTPResponse(200);
response.body = Encoding.UTF8.GetBytes(sb.ToString());
return response;
}
public HTTPResponse PostProcessing(HTTPResponse response)
{
throw new NotImplementedException();
}
}
}
36 changes: 21 additions & 15 deletions Assignments/HW1/DNWS/config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"DocumentRoot": ".",
"Port": "8080",
"Plugins" : [
{
"Path" : "stat",
"Class" : "DNWS.StatPlugin",
"Preprocessing" : "true",
"Postprocessing" : "false" ,
"Singpleton" : "false"
},
{
"Path" : "ox",
"Class" : "DNWS.OXPlugin",
"Preprocessing" : "false",
"Postprocessing" :"false"
}
]
"Plugins": [
{
"Path": "stat",
"Class": "DNWS.StatPlugin",
"Preprocessing": "true",
"Postprocessing": "false",
"Singpleton": "false"
},
{
"Path": "ox",
"Class": "DNWS.OXPlugin",
"Preprocessing": "false",
"Postprocessing": "false"
},
{
"Path": "clintinfo",
"Class": "DNWS.clintinfo",
"Preprocessing": "false",
"Postprocessing": "false"
}
]
}