Statistics
| Branch: | Tag: | Revision:

mongoose / examples / simplest_web_server / simplest_web_server.c @ eaef5bd1

History | View | Annotate | Download (931 Bytes)

1
// Copyright (c) 2015 Cesanta Software Limited
2
// All rights reserved
3

    
4
#include "mongoose.h"
5

    
6
static const char *s_http_port = "8000";
7
static struct mg_serve_http_opts s_http_server_opts;
8

    
9
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
10
  if (ev == MG_EV_HTTP_REQUEST) {
11
    mg_serve_http(nc, (struct http_message *) p, s_http_server_opts);
12
  }
13
}
14

    
15
int main(void) {
16
  struct mg_mgr mgr;
17
  struct mg_connection *nc;
18

    
19
  mg_mgr_init(&mgr, NULL);
20
  printf("Starting web server on port %s\n", s_http_port);
21
  nc = mg_bind(&mgr, s_http_port, ev_handler);
22
  if (nc == NULL) {
23
    printf("Failed to create listener\n");
24
    return 1;
25
  }
26

    
27
  // Set up HTTP server parameters
28
  mg_set_protocol_http_websocket(nc);
29
  s_http_server_opts.document_root = ".";  // Serve current directory
30
  s_http_server_opts.enable_directory_listing = "yes";
31

    
32
  for (;;) {
33
    mg_mgr_poll(&mgr, 1000);
34
  }
35
  mg_mgr_free(&mgr);
36

    
37
  return 0;
38
}