diff --git a/examples/Makefile b/examples/Makefile index f1dac204..46691e31 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,8 +1,7 @@ -PROG= chat CFLAGS= -W -Wall -I.. -pthread -g all: OS=`uname`; \ test "$$OS" = Linux && LIBS="-ldl" ; \ - $(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o $(PROG) - ./$(PROG) + $(CC) $(CFLAGS) hello.c ../mongoose.c $$LIBS $(ADD) -o hello; + $(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o chat diff --git a/examples/hello.c b/examples/hello.c new file mode 100644 index 00000000..d193f935 --- /dev/null +++ b/examples/hello.c @@ -0,0 +1,28 @@ +#include +#include +#include "mongoose.h" + +static void *callback(enum mg_event event, + struct mg_connection *conn, + const struct mg_request_info *request_info) { + if (event == MG_NEW_REQUEST) { + // Echo requested URI back to the client + mg_printf(conn, "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n\r\n" + "%s", request_info->uri); + return ""; // Mark as processed + } else { + return NULL; + } +} + +int main(void) { + struct mg_context *ctx; + const char *options[] = {"listening_ports", "8080", NULL}; + + ctx = mg_start(&callback, NULL, options); + getchar(); // Wait until user hits "enter" + mg_stop(ctx); + + return 0; +}