-
Notifications
You must be signed in to change notification settings - Fork 3
/
hello.c
44 lines (34 loc) · 1.26 KB
/
hello.c
1
#include <string.h>#include "mongoose.h"static void *callback(enum mg_event event, struct mg_connection *conn) { const struct mg_request_info *request_info = mg_get_request_info(conn); printf("\nEntering inside callback function..\n"); if (event == MG_NEW_REQUEST) { char content[1024]; int content_length = snprintf(content, sizeof(content), "Hello from mongoose! Remote port: %d", request_info->remote_port); printf("\nHello from mongoose! Remote port: %d \n\t content length is %d \ncontent is :-",request_info->remote_port,content_length,content); mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Content-Type: text/plain\r\n" "Content-Length: %d\r\n" // Always set Content-Length "\r\n" "%s", content_length, content); // Mark as processed return ""; } else { return NULL; }}int mg_main(void) { struct mg_context *ctx; const char *options[] = {"listening_ports", "8081", NULL}; printf("\n\t Changan Server started with port 8081 \n"); ctx = mg_start(&callback, NULL, options); getchar(); // Wait until user hits "enter" mg_stop(ctx); return 0;}