Statistics
| Branch: | Tag: | Revision:

mongoose / examples / mqtt_broker / mqtt_broker.c @ eaef5bd1

History | View | Annotate | Download (1.3 KB)

1
/*
2
 * Copyright (c) 2014 Cesanta Software Limited
3
 * All rights reserved
4
 * This software is dual-licensed: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License version 2 as
6
 * published by the Free Software Foundation. For the terms of this
7
 * license, see <http://www.gnu.org/licenses/>.
8
 *
9
 * You are free to use this software under the terms of the GNU General
10
 * Public License, but WITHOUT ANY WARRANTY; without even the implied
11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 * See the GNU General Public License for more details.
13
 *
14
 * Alternatively, you can license this software under a commercial
15
 * license, as set out in <https://www.cesanta.com/license>.
16
 */
17

    
18
#include "../../mongoose.h"
19

    
20
int main(void) {
21
  struct mg_mgr mgr;
22
  const char *address = "0.0.0.0:1883";
23
  struct mg_connection *nc;
24
  struct mg_mqtt_broker brk;
25

    
26
  mg_mgr_init(&mgr, NULL);
27
  mg_mqtt_broker_init(&brk, NULL);
28

    
29
  if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
30
    fprintf(stderr, "mg_bind(%s) failed\n", address);
31
    exit(EXIT_FAILURE);
32
  }
33
  nc->user_data = &brk;
34

    
35
  printf("MQTT broker started on %s\n", address);
36

    
37
  /*
38
   * TODO: Add a HTTP status page that shows current sessions
39
   * and subscriptions
40
   */
41

    
42
  for (;;) {
43
    mg_mgr_poll(&mgr, 1000);
44
  }
45
}