Commit 9bd2812f authored by valenok's avatar valenok

Added examples/hello.c - a minimalistic embedding example

parent 377cece9
PROG= chat
CFLAGS= -W -Wall -I.. -pthread -g CFLAGS= -W -Wall -I.. -pthread -g
all: all:
OS=`uname`; \ OS=`uname`; \
test "$$OS" = Linux && LIBS="-ldl" ; \ test "$$OS" = Linux && LIBS="-ldl" ; \
$(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o $(PROG) $(CC) $(CFLAGS) hello.c ../mongoose.c $$LIBS $(ADD) -o hello;
./$(PROG) $(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o chat
#include <stdio.h>
#include <string.h>
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment