hellobrowser.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 enum MHD_Result
  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 **req_cls)
  19. {
  20. const char *page = "<html><body>Hello, browser!</body></html>";
  21. struct MHD_Response *response;
  22. enum MHD_Result ret;
  23. (void) cls; /* Unused. Silent compiler warning. */
  24. (void) url; /* Unused. Silent compiler warning. */
  25. (void) method; /* Unused. Silent compiler warning. */
  26. (void) version; /* Unused. Silent compiler warning. */
  27. (void) upload_data; /* Unused. Silent compiler warning. */
  28. (void) upload_data_size; /* Unused. Silent compiler warning. */
  29. (void) req_cls; /* Unused. Silent compiler warning. */
  30. response = MHD_create_response_from_buffer_static (strlen (page), page);
  31. ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
  32. MHD_destroy_response (response);
  33. return ret;
  34. }
  35. int
  36. main (void)
  37. {
  38. struct MHD_Daemon *daemon;
  39. daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
  40. PORT, NULL, NULL,
  41. &answer_to_connection, NULL, MHD_OPTION_END);
  42. if (NULL == daemon)
  43. return 1;
  44. (void) getchar ();
  45. MHD_stop_daemon (daemon);
  46. return 0;
  47. }