Question

I recently came across embedded mongoose web server library that I plan to use for a project. However, only after spending a lot of time on Google and Stack Overflow was I able to get the basic "hello world" example working in C language.

Now that I am not able to find any online tutorials or existing questions on Stack Overflow about my doubts, I would like to question them here. I have following questions about usage of Mongoose server-:

  • How do I get to know what is requested?

Generally, in more popular servers like Apache when the user calls for "localhost/help.text" he gets "help.txt" displayed in the browser. However, in the embedded version of Mongoose how do I know what the user has requested to that I can pass on that particular file (or raw data in my case) depending upon what was requested by the user?

  • How do I send files and its associations to the client's browser?

From examples, I was able to learn how raw data is sent to the client's browser, however what if I want to send a file. Say for example I send an HTML file are all the assosiated files sent too? Generally, when CSS and javascript files are encountered by the browser it sends another request to the server for those files and then server sends back those file. However, recently I came across this question and it confuses me a little (although I haven't tried what is says): Display html and pass the data from html to mongoose server

  • How do I accept files from the client? As in allowing client to upload something?

I visited the file upload example of Mongoose given on the website, but I couldn't much unserstand what was going on.

These are some very basic features that a server has and perhaps because of scarcity of good tutorials I am not able to find out the solution to my problem while it may be pretty trivial.

On a slightly different note, I would like to learn more about features of Mongoose embedded server and how they can be used.

Pardon me if this question seems very basic, but from the reviews I have read and from what the Mongoose's website says, I think mongoose is a great embedded web server if only a little more documentation of the same could be found.

Thank you.

Was it helpful?

Solution

  • How do I get to know what is requested?

The answer is in the example, https://github.com/cesanta/mongoose/blob/master/examples/hello.c All the information is in the struct mg_connection structure passed to the callback.

  • How do I send files and its associations to the client's browser?

You should not do that directly. Just reply with the HTML page, and browser will request all required files itself by sending separate request per file.

  • How do I accept files from the client? As in allowing client to upload something?

Yes you can upload files. There is an example https://github.com/cesanta/mongoose/blob/master/examples/upload.c on how to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top