Advertisement
Guest User

Untitled

a guest
Dec 6th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. #include <microhttpd.h>
  2. #include <stdio.h>
  3.  
  4. #define PORT 8080
  5.  
  6. static int answer_to_connection(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
  7.                                 const char *version, const char *upload_data, size_t *upload_data_size,
  8.                                 void **con_cls) {
  9.     const char *page = "<html><body>Hello world!</body></html>";
  10.     struct MHD_Response *response;
  11.     int ret;
  12.     response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_PERSISTENT);
  13.     MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html");
  14.  
  15.     //MHD_add_response_header(response, MHD_HTTP_HEADER_CONNECTION, "close");
  16.  
  17.     ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
  18.     MHD_destroy_response(response);
  19.     return ret;
  20. }
  21.  
  22.  
  23. int main() {
  24.     struct MHD_Daemon *daemon;
  25.     daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION, PORT, NULL, NULL,
  26.                               &answer_to_connection, NULL,
  27.                               MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 1,
  28.                               MHD_OPTION_END);
  29.     if (NULL == daemon)
  30.         return 1;
  31.     getchar();
  32.     MHD_stop_daemon(daemon);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement