mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
c# example synced to the current version, and tested
This commit is contained in:
1 parent
fe95707b4e
commit
f9f623bd60
2 files changed
+56
-71
No files matched your search
+19
-9
@@ -5,23 +5,33 @@ using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Program {
|
||||
static private int RequestHandler(MongooseConnection conn) {
|
||||
return 0;
|
||||
/*
|
||||
conn.write("HTTP/1.1 200 OK\r\n\r\n");
|
||||
conn.write("Hello from C#!\n");
|
||||
conn.write("Your user-agent is: " + conn.get_header("User-Agent") + "\n");
|
||||
*/
|
||||
static private int EventHandler(MongooseEvent ev) {
|
||||
if (ev.type != 1) {
|
||||
return 0; // Mark as unhandled
|
||||
}
|
||||
|
||||
MongooseRequestInfo request_info = (MongooseRequestInfo)
|
||||
Marshal.PtrToStructure(ev.request_info, typeof(MongooseRequestInfo));
|
||||
|
||||
if (request_info.uri != "/test") {
|
||||
return 0; // Mark as unhandled
|
||||
}
|
||||
|
||||
Mongoose.write(ev.conn, "HTTP/1.1 200 OK\r\n\r\n");
|
||||
Mongoose.write(ev.conn, "Hello from C#!\n");
|
||||
|
||||
return 1; // Mark as handled
|
||||
}
|
||||
|
||||
static void Main() {
|
||||
Mongoose web_server = new Mongoose("c:\\", "8080",
|
||||
new MongooseBeginRequest(RequestHandler));
|
||||
Mongoose web_server = new Mongoose(".", "9000",
|
||||
new MongooseEventHandler(EventHandler));
|
||||
|
||||
Console.WriteLine("Mongoose v." + web_server.version_ + " started.");
|
||||
Console.WriteLine("Press enter to exit program.");
|
||||
|
||||
// Serve requests until user presses "enter" on a keyboard
|
||||
Console.ReadLine();
|
||||
web_server.stop();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user