Removed the configuration with an App.config file from the HttpServer class

This commit is contained in:
sta
2013-07-24 17:23:48 +09:00
parent 998a296d18
commit cd7dfea62d
4 changed files with 103 additions and 140 deletions

View File

@@ -49,6 +49,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />

View File

@@ -1,4 +1,5 @@
using System;
using System.Configuration;
using WebSocketSharp;
using WebSocketSharp.Net;
using WebSocketSharp.Server;
@@ -9,59 +10,59 @@ namespace Example3
{
private static HttpServer _httpsv;
public static void Main(string[] args)
public static void Main (string [] args)
{
_httpsv = new HttpServer(4649);
_httpsv = new HttpServer (4649);
#if DEBUG
_httpsv.Log.Level = LogLevel.TRACE;
#endif
//_httpsv.RootPath = "../../Public";
_httpsv.RootPath = ConfigurationManager.AppSettings ["RootPath"];
//_httpsv.Sweeping = false;
_httpsv.AddWebSocketService<Echo>("/Echo");
_httpsv.AddWebSocketService<Chat>("/Chat");
_httpsv.AddWebSocketService<Echo> ("/Echo");
_httpsv.AddWebSocketService<Chat> ("/Chat");
_httpsv.OnGet += (sender, e) =>
{
onGet(e);
onGet (e);
};
_httpsv.OnError += (sender, e) =>
{
Console.WriteLine(e.Message);
Console.WriteLine (e.Message);
};
_httpsv.Start();
Console.WriteLine("HTTP Server listening on port: {0} service path:", _httpsv.Port);
_httpsv.Start ();
Console.WriteLine ("HTTP Server listening on port: {0} service path:", _httpsv.Port);
foreach (var path in _httpsv.ServicePaths)
Console.WriteLine(" {0}", path);
Console.WriteLine();
Console.WriteLine (" {0}", path);
Console.WriteLine ();
Console.WriteLine("Press enter key to stop server...");
Console.ReadLine();
Console.WriteLine ("Press enter key to stop the server...");
Console.ReadLine ();
_httpsv.Stop();
_httpsv.Stop ();
}
private static byte[] getContent(string path)
private static byte [] getContent (string path)
{
if (path == "/")
path += "index.html";
return _httpsv.GetFile(path);
return _httpsv.GetFile (path);
}
private static void onGet(HttpRequestEventArgs eventArgs)
private static void onGet (HttpRequestEventArgs eventArgs)
{
var request = eventArgs.Request;
var request = eventArgs.Request;
var response = eventArgs.Response;
var content = getContent(request.RawUrl);
var content = getContent (request.RawUrl);
if (content != null)
{
response.WriteContent(content);
response.WriteContent (content);
return;
}
response.StatusCode = (int)HttpStatusCode.NotFound;
response.StatusCode = (int) HttpStatusCode.NotFound;
}
}
}