-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (44 loc) · 2.22 KB
/
Program.cs
File metadata and controls
53 lines (44 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// FILE : Program.cs
// PROJECT : MyOwnWebServer
// PROGRAMMER : Gaurav Patel
// FIRST VERSION : 12-11-2024
// DESCRIPTION : This is the starting point of a custom web server application whether it is a single-threaded or multithreaded application. It handles the options for SERVER settings received by the system through the command line interface.
using System;
namespace MyOwnWebServer
{
// FILE : Program.cs
// PROJECT : WebServer
// PROGRAMMER : Gaurav Patel
// FIRST VERSION : 12-11-2024
// DESCRIPTION : This is the starting point of a custom web server application whether it is a single-threaded or multithreaded application. It handles the options for SERVER settings received by the system through the command line interface and starts the web server.
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Starting WebServer ...");
// Typically used to parse the command line arguments and then uses the information obtained to setup the WebServer class.
if (args.Length != 3)
{
Console.WriteLine("Usage: WebServer and –root=<webRoot> and –ip=<serverIP> and –port=<serverPort>");
return;
}
string webRoot = null;
string serverIP = null;
int serverPort = 0;
foreach (var arg in args)
{
if (arg.StartsWith("-root=")) webRoot = arg.Substring(6);
else if (arg.StartsWith("-ip=")) serverIP = arg.Substring(4);
else if (arg.StartsWith("-port=")) serverPort = int.Parse(arg.Substring(6));
}
if (string.IsNullOrEmpty(webRoot) || string.IsNullOrEmpty(serverIP) || serverPort == 0)
{
Console.WriteLine("It can also be false or not valid arguments provided.");
return;
}
// initialize the server for staet
WebServer server = new WebServer(webRoot, serverIP, serverPort);
server.RunServer();
}
}
}