This repository was archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (43 loc) · 1.37 KB
/
Program.cs
File metadata and controls
47 lines (43 loc) · 1.37 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
using System.Net;
namespace PainterPro
{
public static class Program
{
public static void Main()
{
// Certificate setup: https://stackoverflow.com/a/33905011
// Note to self: Certbot makes certificates, openssl combines certificate and key to .pfx file,
// wich is loaded in with Windows MMC, and then bound to app with netsh http add sslcert. Phew!
HttpListener listener = new HttpListener();
listener.Prefixes.Add("https://+:443/");
listener.Start();
listener.Listen();
}
public static void Listen(this HttpListener listener)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Server running...");
#if DEBUG
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" (Debug mode enabled)");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("DO NOT USE DEBUG MODE IN PRODUCTION!");
#else
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" (Debug mode disabled)");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Run in debug mode for logging.");
#endif
Console.ForegroundColor = ConsoleColor.White;
while (true)
{
HttpListenerContext context = listener.GetContext();
#if DEBUG
context.HandleConnection(); // Handles connection synchronously.
#else
Task.Run(() => context.HandleConnection()); // Handles connection asynchronously.
#endif
}
}
}
}