2014-09-10 05:46:24 +08:00
|
|
|
// Copyright (c) 2014 Cesanta Software
|
|
|
|
// All rights reserved
|
|
|
|
//
|
|
|
|
// This example demostrates basic use of Mongoose embedded web server.
|
2014-09-10 06:20:23 +08:00
|
|
|
// $Date: 2014-09-09 22:20:23 UTC $
|
2014-09-10 05:46:24 +08:00
|
|
|
|
2011-06-18 07:29:46 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "mongoose.h"
|
|
|
|
|
2014-03-02 20:16:09 +08:00
|
|
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
2014-09-10 05:44:57 +08:00
|
|
|
switch (ev) {
|
|
|
|
case MG_AUTH: return MG_TRUE;
|
|
|
|
case MG_REQUEST:
|
|
|
|
mg_printf_data(conn, "Hello! Requested URI is [%s]", conn->uri);
|
|
|
|
return MG_TRUE;
|
|
|
|
default: return MG_FALSE;
|
2014-03-02 20:16:09 +08:00
|
|
|
}
|
2011-06-18 07:29:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2013-12-16 21:33:50 +08:00
|
|
|
struct mg_server *server;
|
2013-02-02 00:48:30 +08:00
|
|
|
|
2013-12-16 21:33:50 +08:00
|
|
|
// Create and configure the server
|
2014-03-02 20:16:09 +08:00
|
|
|
server = mg_create_server(NULL, ev_handler);
|
2013-12-16 21:33:50 +08:00
|
|
|
mg_set_option(server, "listening_port", "8080");
|
2011-06-18 07:29:46 +08:00
|
|
|
|
2013-12-16 21:33:50 +08:00
|
|
|
// Serve request. Hit Ctrl-C to terminate the program
|
|
|
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
|
|
|
for (;;) {
|
|
|
|
mg_poll_server(server, 1000);
|
|
|
|
}
|
2013-02-02 00:48:30 +08:00
|
|
|
|
2013-12-16 21:33:50 +08:00
|
|
|
// Cleanup, and free server instance
|
|
|
|
mg_destroy_server(&server);
|
2011-06-18 07:29:46 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|