本文整理汇总了C#中HttpServer.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.Add方法的具体用法?C# HttpServer.Add怎么用?C# HttpServer.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Template generators are used to render templates
// (convert code + html to pure html).
TemplateManager mgr = new TemplateManager();
mgr.Add("haml", new HamlGenerator());
// The httpserver is quite dumb and will only serve http, nothing else.
HttpServer server = new HttpServer();
// a controller mode implements a MVC pattern
// You'll add all controllers to the same module.
ControllerModule mod = new ControllerModule();
mod.Add(new UserController(mgr));
server.Add(mod);
// file module will be handling files
FileModule fh = new FileModule("/", Environment.CurrentDirectory);
fh.AddDefaultMimeTypes();
server.Add(fh);
// Let's start pure HTTP, we can also start a HTTPS listener.
server.Start(IPAddress.Any, 8081);
Console.ReadLine();
}
示例2: CreateHTTPServer
public static void CreateHTTPServer(string filePath, string httpServerPath,
string PHPCGIPath, uint port, bool allowDirectoryListing)
{
HttpServer server = new HttpServer();
AdvancedFileModule afm = new AdvancedFileModule(httpServerPath, filePath, false, allowDirectoryListing);
afm.ServeUnknownTypes(true, "php");
afm.AddCgiApplication("php", PHPCGIPath);
server.Add(afm);
server.Start(IPAddress.Any, (int)port);
}
示例3: Test
public void Test()
{
HttpServer server = new HttpServer();
server.Add(new SimpleModule());
server.Start(IPAddress.Any, 8899);
server.BackLog = 50;
Thread[] threads = new Thread[ThreadCount];
for (int i = 0; i < ThreadCount; ++i)
{
threads[i] = new Thread(OnSendRequest);
threads[i].Start(i+1);
}
if (!_threadsDoneEvent.WaitOne(60000, true))
Console.WriteLine("Failed to get all responses.");
foreach (string s in _failedThreads)
Console.WriteLine("* Failed thread: " + s);
if (_failedThreads.Count > 0)
Console.WriteLine("* Total: " + _failedThreads.Count);
Console.ReadLine();
}
示例4: Initialize
public void Initialize()
{
if (_server == null)
{
_port = getFreePort();
_server = new HttpServer(new MyLogWriter());
_server.Add(new MyModule(this));
_server.Start(IPAddress.Loopback, _port);
Trace.WriteLine(
string.Format(
@"[Web server] Started local web server for URL '{0}'.",
baseUrl));
}
}