-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicWebServerSample.cs
More file actions
61 lines (51 loc) · 1.85 KB
/
BasicWebServerSample.cs
File metadata and controls
61 lines (51 loc) · 1.85 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
54
55
56
57
58
59
60
61
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using NetduinoLab.Web;
using NetduinoLab.Common;
using NetduinoLab.Web.Abstract;
namespace NetduinoLab.Device
{
public class Program
{
public static void Main()
{
var program = new Program();
int webServerDuration = 600000;
FileLogger fileLogger = null;
try
{
NtpUtility.RetrieveNtpTime();
Utility.SetLocalTime(NtpUtility.NtpTime);
string filePath = FileSystem.RootDirectory + @"\" + "WebServer.log";
long maxFileSize = 4000;
bool isRolling = false;
fileLogger = FileLogger.Create(filePath, maxFileSize, isRolling);
fileLogger.Log(Severity.Info, "Initializing web server.");
using (var webServer = new WebServer(fileLogger))
{
webServer.AddRouteHandler(new RouteHandler(
//Url for this is http://<device-ip-or-hostname>/test...
HttpMethod.Get, "test", program.handleTestRequest));
webServer.Start();
Thread.Sleep(webServerDuration);
}
fileLogger.Log(Severity.Info, "Web server shut down.");
}
catch (Exception exception)
{
if (fileLogger != null)
fileLogger.Log(Severity.Error, exception.ToString());
}
}
private void handleTestRequest(
HttpRequestContext requestContext, IHttpResponse response)
{
response.Send(
HttpResponseStatus.OK, HttpContentType.TextHtml, "<h1>Test succeeded!</h1>");
}
}
}