hello_world.c 956 Bytes
Newer Older
Sergey Lyubka's avatar
Sergey Lyubka committed
1 2 3 4
// Copyright (c) 2014 Cesanta Software
// All rights reserved
//
// This example demostrates basic use of Mongoose embedded web server.
5
// $Date: 2014-09-09 22:20:23 UTC $
Sergey Lyubka's avatar
Sergey Lyubka committed
6

7 8 9 10
#include <stdio.h>
#include <string.h>
#include "mongoose.h"

11
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
12 13 14 15 16 17
  switch (ev) {
    case MG_AUTH: return MG_TRUE;
    case MG_REQUEST:
      mg_printf_data(conn, "Hello! Requested URI is [%s]", conn->uri);
      return MG_TRUE;
    default: return MG_FALSE;
18
  }
19 20 21
}

int main(void) {
22
  struct mg_server *server;
23

24
  // Create and configure the server
25
  server = mg_create_server(NULL, ev_handler);
26
  mg_set_option(server, "listening_port", "8080");
27

28 29 30 31 32
  // Serve request. Hit Ctrl-C to terminate the program
  printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
  for (;;) {
    mg_poll_server(server, 1000);
  }
33

34 35
  // Cleanup, and free server instance
  mg_destroy_server(&server);
36 37 38

  return 0;
}