hellobrowser.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Feel free to use this example code in any way
  2. you see fit (Public Domain) */
  3. #include <sys/types.h>
  4. #ifndef _WIN32
  5. #include <sys/select.h>
  6. #include <sys/socket.h>
  7. #else
  8. #include <winsock2.h>
  9. #endif
  10. #include <string.h>
  11. #include <microhttpd.h>
  12. #include <stdio.h>
  13. #define PORT 8888
  14. static int
  15. answer_to_connection (void *cls, struct MHD_Connection *connection,
  16. const char *url, const char *method,
  17. const char *version, const char *upload_data,
  18. size_t *upload_data_size, void **con_cls)
  19. {
  20. const char *page = "<html><body>Hello, browser!</body></html>";
  21. struct MHD_Response *response;
  22. int ret;
  23. response =
  24. MHD_create_response_from_buffer (strlen (page), (void *) page,
  25. MHD_RESPMEM_PERSISTENT);
  26. ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  27. MHD_destroy_response (response);
  28. return ret;
  29. }
  30. int
  31. main ()
  32. {
  33. struct MHD_Daemon *daemon;
  34. daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL,
  35. &answer_to_connection, NULL, MHD_OPTION_END);
  36. if (NULL == daemon)
  37. return 1;
  38. (void) getchar ();
  39. MHD_stop_daemon (daemon);
  40. return 0;
  41. }