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