Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:21:18+00:00 2026-05-20T09:21:18+00:00

I came across an embedded web server named mongoose and http://code.google.com/p/mongoose/ and I read

  • 0

I came across an embedded web server named mongoose and http://code.google.com/p/mongoose/ and I read the wiki it was great and i searched for some sample hello world program but i couldn’t find it… i found some example but that was written in c++ for windows and can any one provide an example c program to run this webserver..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:21:19+00:00Added an answer on May 20, 2026 at 9:21 am

    It is quite simple, first you need to implement the call back function:

    void *event_handler(enum mg_event event,
        struct mg_connection *conn) {
    
        const struct mg_request_info *request_info = mg_get_request_info(conn);
    
        static void* done = "done";
    
        if (event == MG_NEW_REQUEST) {
            if (strcmp(request_info->uri, "/hello") == 0) {
                // handle c[renderer] request
                if(strcmp(request_info->request_method, "GET") != 0) {
                    // send error (we only care about HTTP GET)
                    mg_printf(conn, "HTTP/1.1 %d Error (%s)\r\n\r\n%s",
                        500,
                        "we only care about HTTP GET",
                        "we only care about HTTP GET");
                    // return not null means we handled the request
                    return done;
                }
    
                // handle your GET request to /hello
                char* content = "Hello World!";
                char* mimeType = "text/plain";
                int contentLength = strlen(content);
    
                mg_printf(conn,
                    "HTTP/1.1 200 OK\r\n"
                    "Cache: no-cache\r\n"
                    "Content-Type: %s\r\n"
                    "Content-Length: %d\r\n"
                    "\r\n",
                    mimeType,
                    contentLength);
                mg_write(conn, content, contentLength);
                return done;
                }
            }
            // in this example i only handle /hello
            mg_printf(conn, "HTTP/1.1 %d Error (%s)\r\n\r\n%s",
                500, /* This the error code you want to send back*/
                "Invalid Request.",
                "Invalid Request.");
            return done;
        }
    
        // No suitable handler found, mark as not processed. Mongoose will
        // try to serve the request.
        return NULL;
    }
    

    Then you need to start the server:

    int main(int argc, char **argv) {
    
        /* Default options for the HTTP server */
        const char *options[] = {
            "listening_ports", "8081",
            "num_threads", "10",
            NULL
        };
    
        /* Initialize HTTP layer */
        static struct mg_context *ctx;
    
        ctx = mg_start(&event_handler, options);
        if(ctx == NULL) {
            exit(EXIT_FAILURE);
        }
    
        puts("Server running, press enter to exit\n");
        getchar();
        mg_stop(ctx);
    
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across materialized views, which look great: http://en.oreilly.com/mysql2011/public/schedule/detail/17146 However there is too much
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
Came across this implementation of FxAA from NVidia. http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf http://timothylottes.blogspot.in/2011/12/fxaa-40-stills-and-features.html The source code as
I came across this Linq to Sql code in an application I am maintaining:
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I came across this due to a bug in my code and I'm curious
I came across the below lines in code unsigned char A = 0xB9; unsigned
I came across the following code : int i; for(; scanf(%s, &i);) printf(hello); As
I came across this code in ShareKit, and I don't understand what the writer
I came across some java code for doing a prefix search on a JList.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.