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

600611029 #25

Open
wants to merge 6 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
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\Assignments",
"\\Assignments\\HW1",
"\\Assignments\\HW1\\DNWS"
],
"SelectedNode": "\\Assignments\\HW1\\DNWS\\Program.cs",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
1 change: 1 addition & 0 deletions 261433
Submodule 261433 added at e93b79
1 change: 1 addition & 0 deletions Assignments/HW1/261433
Submodule 261433 added at ca1879
Binary file added Assignments/HW1/DNWS/.vs/DNWS/v15/.suo
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
54 changes: 54 additions & 0 deletions Assignments/HW1/DNWS/Clientinfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.IO;
using System.Diagnostics;

namespace DNWS
{
class ClientInfo : IPlugin
{
public ClientInfo()
{

}

public void PreProcessing(HTTPRequest request)
{
throw new NotImplementedException();
}

public HTTPResponse GetResponse(HTTPRequest request)//ref. 600611030
{
HTTPResponse response = null;
StringBuilder sb = new StringBuilder();
string[] remoteEndpoint = request.getPropertyByKey("RemoteEndPoint").Split(':');
string ip = remoteEndpoint[0], port = remoteEndpoint[1];
sb.Append("<html><body>Client IP: " + ip + "</br></br>");
sb.Append("Client Port: " + port + "</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") + "</br></br>");
sb.Append("Thread ID: " + Thread.CurrentThread.ManagedThreadId + "</br></br>");
//from https://stackoverflow.com/questions/15381174/how-to-count-the-amount-of-concurrent-threads-in-net-application
sb.Append("Amount of thread: " + Process.GetCurrentProcess().Threads.Count + "</br></br>");
ThreadPool.GetAvailableThreads(out int workers, out int completion);
ThreadPool.GetMaxThreads(out int max_workers, out int max_completion);
sb.Append("Size of thread pool: " + max_workers + "<br /><br />");
sb.Append("Available threads in thread pool: " + workers + "<br /><br />");
sb.Append("Active threads in thread pool: " + (max_workers - workers) + "<br /><br />");
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();
}
}
}
25 changes: 25 additions & 0 deletions Assignments/HW1/DNWS/DNWS.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DNWS", "DNWS.csproj", "{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE9DB1C1-4B6D-4646-85E9-CADAB441EB52}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF126B8E-0932-4255-8960-735157571F53}
EndGlobalSection
EndGlobal
5 changes: 3 additions & 2 deletions Assignments/HW1/DNWS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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)
{
NetworkStream ns = new NetworkStream(_client);
string requestStr = "";
Expand Down Expand Up @@ -288,7 +288,8 @@ public void Start()
_parent.Log("Client accepted:" + clientSocket.RemoteEndPoint.ToString());
HTTPProcessor hp = new HTTPProcessor(clientSocket, _parent);
// Single thread
hp.Process();
ThreadPool.SetMaxThreads(50, 50);
ThreadPool.QueueUserWorkItem(hp.Process);
// End single therad

}
Expand Down
13 changes: 10 additions & 3 deletions Assignments/HW1/DNWS/StatPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace DNWS
{
Expand Down Expand Up @@ -30,9 +32,14 @@ public void PreProcessing(HTTPRequest request)
public HTTPResponse GetResponse(HTTPRequest request)
{
HTTPResponse response = null;
StringBuilder sb = new StringBuilder();
sb.Append("<html><body><h1>Stat:</h1>");
foreach (KeyValuePair<String, int> entry in statDictionary)
ThreadPool.GetAvailableThreads(out int workers, out int completion);
ThreadPool.GetMaxThreads(out int max_workers, out int max_completion);
StringBuilder sb = new StringBuilder();
sb.Append("<html><body><h1>Stat:</h1><br/>");
sb.Append("Size of Threads: " + max_workers + "<br /><br />");
sb.Append("Available Threads: " + workers + "<br /><br />");
sb.Append("Active threads: " + (max_workers - workers) + "<br /><br />");
foreach (KeyValuePair<String, int> entry in statDictionary)
{
sb.Append(entry.Key + ": " + entry.Value.ToString() + "<br />");
}
Expand Down
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": "clientinfo",
"Class": "DNWS.Clientinfo",
"Preprocessing": "false",
"Postprocessing": "false"
}
]
}