-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHttpServer.cs
42 lines (38 loc) · 1.26 KB
/
HttpServer.cs
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
using System;
using System.IO;
using System.Net;
namespace GLSI
{
class HttpServer
{
public void Start()
{
try
{
HttpListener httpListener = new HttpListener();
// https://stackoverflow.com/questions/36846535/c-sharp-http-listener-not-listening-on-localhost-only-works-with-fqdn
//TODO This Fixed the problem
httpListener.Prefixes.Add("http://10.0.0.32:6666/httpTest/");
httpListener.Start();
while (true)
{
Console.WriteLine("Waiting...");
HttpListenerContext context = httpListener.GetContext();
using (Stream stream = context.Response.OutputStream)
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(
"<HTML><BODY>The time is currently</BODY></HTML>");
}
}
Console.WriteLine("Sent");
}
}
catch (WebException e)
{
Console.WriteLine(e.Status);
}
}
}
}