{"id":13418266,"url":"https://github.com/cesanta/mongoose","last_synced_at":"2025-05-14T09:06:19.966Z","repository":{"id":4284914,"uuid":"5414488","full_name":"cesanta/mongoose","owner":"cesanta","description":"Embedded web server, with TCP/IP network stack, MQTT and Websocket","archived":false,"fork":false,"pushed_at":"2025-05-13T21:26:43.000Z","size":38796,"stargazers_count":11683,"open_issues_count":3,"forks_count":2787,"subscribers_count":468,"default_branch":"master","last_synced_at":"2025-05-14T09:03:13.452Z","etag":null,"topics":["embedded","http","iot","mqtt","tcp","tcpip","tls13","udp","web-server","webserver","websocket"],"latest_commit_sha":null,"homepage":"https://mongoose.ws","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cesanta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-08-14T15:09:51.000Z","updated_at":"2025-05-14T07:55:24.000Z","dependencies_parsed_at":"2023-12-18T22:27:15.596Z","dependency_job_id":"b7fb7892-0691-4136-bd21-9433ea445bf4","html_url":"https://github.com/cesanta/mongoose","commit_stats":{"total_commits":4837,"total_committers":168,"mean_commits":"28.791666666666668","dds":0.4914203018399834,"last_synced_commit":"8eabf4352549295edc2a9e155f6cb9fa8806beb7"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesanta%2Fmongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesanta%2Fmongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesanta%2Fmongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesanta%2Fmongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cesanta","download_url":"https://codeload.github.com/cesanta/mongoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded","http","iot","mqtt","tcp","tcpip","tls13","udp","web-server","webserver","websocket"],"created_at":"2024-07-30T22:01:00.323Z","updated_at":"2025-05-14T09:06:19.942Z","avatar_url":"https://github.com/cesanta.png","language":"C","readme":"# Mongoose - Embedded Web Server / Embedded Network Library\n\n[![License: GPLv2/Commercial](https://img.shields.io/badge/License-GPLv2%20or%20Commercial-green.svg)](https://opensource.org/licenses/gpl-2.0.php)\n[![Build Status]( https://github.com/cesanta/mongoose/workflows/build/badge.svg)](https://github.com/cesanta/mongoose/actions)\n[![Code Coverage](https://codecov.io/gh/cesanta/mongoose/branch/master/graph/badge.svg)](https://codecov.io/gh/cesanta/mongoose)\n[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/mongoose.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened\u0026can=1\u0026q=proj:mongoose)\n[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20Mongoose%20Guru-006BFF)](https://gurubase.io/g/mongoose)\n\nMongoose is a network library for C/C++.  It provides event-driven non-blocking\nAPIs for TCP, UDP, HTTP, WebSocket, MQTT, and other protocols.  It is designed\nfor connecting devices and bringing them online. On the market since 2004, used\nby vast number of open source and commercial products - it even runs on the\nInternational Space Station!  Mongoose makes embedded network programming fast,\nrobust, and easy. Features include:\n\n- Cross-platform:\n  - works on Linux/UNIX, MacOS, Windows, Android\n  - works on ST, NXP, ESP32, Nordic, TI, Microchip, Infineon, Renesas and other chips\n  - write code once - and it'll work everywhere\n  - ideal for the unification of the network infrastructure code across company\n- Built-in protocols: plain TCP/UDP, SNTP, HTTP, MQTT, Websocket, and other\n- Asynchronous DNS resolver\n- Tiny static and run-time footprint\n- Source code is both ISO C and ISO C++ compliant\n- Easy to integrate: just copy [mongoose.c](https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.c)\n  and [mongoose.h](https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.h) files to your source tree\n- Built-in TCP/IP stack with drivers for bare metal or RTOS systems\n   - Available drivers: STM32F, STM32H; NXP RT1xxx; TI TM4C; Microchip SAME54; Wiznet W5500\n   - A complete Web device dashboard on bare metal ST Nucleo boards is only 6 files\n   - For comparison, a CubeIDE generated HTTP example is 400+ files\n- Can run on top of an existing TCP/IP stack with BSD API, e.g. lwIP, Zephyr, Azure, etc\n- Built-in TLS 1.3 ECC stack. Also can use external TLS libraries - mbedTLS, OpenSSL, or other\n- Does not depend on any other software to implement networking\n- Built-in firmware updates for STM32 H5, STM32 H7\n\nSee https://mongoose.ws/ for complete documentation, videos, case studies, etc.\n\n## Usage Examples\n\nBelow are quick snippets that should give an idea how simple the API is and\nhow easy it is to create applications with it.\n\nCreate a simple web server that serves a directory. The behavior of the\nHTTP server is specified by its event handler function:\n\n```c\n#include \"mongoose.h\"   // To build, run: cc main.c mongoose.c\n\n// HTTP server event handler function\nvoid ev_handler(struct mg_connection *c, int ev, void *ev_data) {\n  if (ev == MG_EV_HTTP_MSG) {\n    struct mg_http_message *hm = (struct mg_http_message *) ev_data;\n    struct mg_http_serve_opts opts = { .root_dir = \"./web_root/\" };\n    mg_http_serve_dir(c, hm, \u0026opts);\n  }\n}\n\nint main(void) {\n  struct mg_mgr mgr;  // Declare event manager\n  mg_mgr_init(\u0026mgr);  // Initialise event manager\n  mg_http_listen(\u0026mgr, \"http://0.0.0.0:8000\", ev_handler, NULL);  // Setup listener\n  for (;;) {          // Run an infinite event loop\n    mg_mgr_poll(\u0026mgr, 1000);\n  }\n  return 0;\n}\n```\n\nHTTP server implements a REST API that returns current time. JSON formatting:\n```c\nstatic void ev_handler(struct mg_connection *c, int ev, void *ev_data) {\n  if (ev == MG_EV_HTTP_MSG) {\n    struct mg_http_message *hm = (struct mg_http_message *) ev_data;\n    if (mg_match(hm-\u003euri, mg_str(\"/api/time/get\"), NULL)) {\n      mg_http_reply(c, 200, \"\", \"{%m:%lu}\\n\", MG_ESC(\"time\"), time(NULL));\n    } else {\n      mg_http_reply(c, 500, \"\", \"{%m:%m}\\n\", MG_ESC(\"error\"), MG_ESC(\"Unsupported URI\")); \n    }\n  }\n}\n```\n\nMQTT client that subscribes to a topic `device1/rx` and\nechoes incoming messages to `device1/tx`:\n\n```c\n#include \"mongoose.h\"\n\nstatic const char *s_mqtt_url = \"mqtt://broker.hivemq.com:1883\";\nstatic struct mg_connection *s_mqtt_conn = NULL;\n\n// MQTT connection event handler function\nstatic void ev_handler(struct mg_connection *c, int ev, void *ev_data) {\n  if (ev == MG_EV_OPEN) {\n    MG_INFO((\"%lu created, connecting to %s ...\", c-\u003eid, s_mqtt_url));\n  } else if (ev == MG_EV_MQTT_OPEN) {\n    struct mg_mqtt_opts opts = {.qos = 1, .topic = mg_str(\"device1/rx\")};\n    mg_mqtt_sub(c, \u0026opts);\n    MG_INFO((\"%lu connected, subscribing to %s\", c-\u003eid, opts.topic.buf));\n  } else if (ev == MG_EV_MQTT_MSG) {\n    char response[100];\n    struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;\n    struct mg_mqtt_opts opts = {.qos = 1, .topic = mg_str(\"device1/tx\")};\n    mg_snprintf(response, sizeof(response), \"Received [%.*s] / [%.*s]\",\n                mm-\u003etopic.len, mm-\u003etopic.buf, mm-\u003edata.len, mm-\u003edata.buf);\n    opts.message = mg_str(response);\n    mg_mqtt_pub(c, \u0026opts);\n  } else if (ev == MG_EV_CLOSE) {\n    MG_INFO((\"%u closing\", c-\u003eid));\n    s_mqtt_conn = NULL;\n  }\n}\n\n// Reconnection timer function. If we get disconnected, reconnect again\nstatic void timer_fn(void *arg) {\n  struct mg_mgr *mgr = (struct mg_mgr *) arg;\n  if (s_mqtt_conn == NULL) {\n    struct mg_mqtt_opts opts = {.clean = true};\n    s_mqtt_conn = mg_mqtt_connect(mgr, s_mqtt_url, \u0026opts, ev_handler, NULL);\n  }\n}\n\nint main() {\n  struct mg_mgr mgr;  // Mongoose event manager. Holds all connections\n  mg_mgr_init(\u0026mgr);  // Initialise event manager\n  mg_timer_add(\u0026mgr, 3000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, \u0026mgr);\n  for (;;) {\n    mg_mgr_poll(\u0026mgr, 1000);  // Infinite event loop\n  }\n  return 0;\n}\n```\n\n## Commercial use\n- Mongoose is used by hundreds of businesses, from Fortune500 giants like\n  Siemens, Schneider Electric, Broadcom, Bosch, Google, Samsung, Qualcomm, Caterpillar to the small businesses\n- Used to solve a wide range of business needs, like implementing Web UI\n  interface on devices, RESTful API services, telemetry data exchange, remote\n  control for a product, remote software updates, remote monitoring, and others\n- Deployed to hundreds of millions devices in production environment worldwide\n- See [Case Studies](https://mongoose.ws/case-studies/) from our respected\n  customers like [Schneider Electric](https://mongoose.ws/case-studies/schneider-electric/) (industrial automation), [Broadcom](https://mongoose.ws/case-studies/broadcom/) (semiconductors), [Pilz](https://mongoose.ws/case-studies/pilz/) (industrial automation), and others\n- See [Testimonials](https://mongoose.ws/testimonials/) from engineers that integrated Mongoose in their commercial products\n- We provide [Evaluation and Commercial licensing](https://mongoose.ws/licensing/), [support](https://mongoose.ws/support/), consultancy and [integration\n  services](https://mongoose.ws/integration/) - don't hesitate to [contact us](https://mongoose.ws/contact/)\n\n\n## Security\n\nWe take security seriously:\n1. Mongoose repository runs a\n  [continuous integration test powered by GitHub](https://github.com/cesanta/mongoose/actions),\n  which runs through hundreds of unit tests on every commit to the repository.\n  Our [unit tests](https://github.com/cesanta/mongoose/tree/master/test)\n  are built with modern address sanitizer technologies, which help to find\n  security vulnerabilities early\n2. Mongoose repository is integrated into Google's\n  [oss-fuzz continuous fuzzer](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened\u0026can=1\u0026q=proj:mongoose)\n  which scans for potential vulnerabilities continuously\n3.  We receive periodic vulnerability reports from the independent security\n  groups like\n  [Cisco Talos](https://www.cisco.com/c/en/us/products/security/talos.html),\n  [Microsoft Security Response Center](https://www.microsoft.com/en-us/msrc),\n  [MITRE Corporation](https://www.mitre.org/),\n  [Compass Security](https://www.compass-security.com/en/) and others.\n  In case of the vulnerability found, we act according to the industry best\n  practice: hold on to the publication, fix the software and notify all our\n  customers that have an appropriate subscription\n4. Some of our customers (for example NASA)\n  have specific security requirements and run independent security audits,\n  of which we get notified and in case of any issue, act similar to (3).\n\n\n## Articles\n\nTechnical guides and deep dives into embedded web servers, WebUI integration and embedded networking technologies:\n- [Embedded Web Server: A Comprehensive Guide for Modern Connected Devices](https://mongoose.ws/articles/embedded-web-server-a-comprehensive-guide-for-modern-connected-devices/)\n- [Building Embedded Web Device Dashboards](https://mongoose.ws/articles/building-embedded-web-device-dashboard/)\n- [ESP32 Device Dashboard: A Step-by-Step Guide for Developers](https://mongoose.ws/articles/esp32-device-dashboard/)\n\n\n## Contributions\n\nContributions are welcome! Please follow the guidelines below:\n\n- Sign [Cesanta CLA](https://cesanta.com/cla.html) and send GitHub pull request\n- Make sure that PRs have only one commit, and deal with one issue only\n","funding_links":[],"categories":["C","Networking","Tools per Language","Install from Source","硬件_其他","内存分配","网络","IoT 笔记","Protocols"],"sub_categories":["C","Network Tools","网络服务_其他","网络","编程环境","Web Server"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesanta%2Fmongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesanta%2Fmongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesanta%2Fmongoose/lists"}