hello.c 730 B

12345678910111213141516171819202122232425262728
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "mongoose.h"
  4. static void *callback(enum mg_event event,
  5. struct mg_connection *conn,
  6. const struct mg_request_info *request_info) {
  7. if (event == MG_NEW_REQUEST) {
  8. // Echo requested URI back to the client
  9. mg_printf(conn, "HTTP/1.1 200 OK\r\n"
  10. "Content-Type: text/plain\r\n\r\n"
  11. "%s", request_info->uri);
  12. return ""; // Mark as processed
  13. } else {
  14. return NULL;
  15. }
  16. }
  17. int main(void) {
  18. struct mg_context *ctx;
  19. const char *options[] = {"listening_ports", "8080", NULL};
  20. ctx = mg_start(&callback, NULL, options);
  21. getchar(); // Wait until user hits "enter"
  22. mg_stop(ctx);
  23. return 0;
  24. }