PDA

View Full Version : Web page for software configuration.


Nick
01-22-2008, 07:31 AM
Hi all,

I've been using .ini files for some time now to configure my software, but it's becoming quite annoying to work with. I'd like to have something graphical with drop-down lists, radio buttons and checkboxes. And ideally I would like it to be interactive, and remote. That would allow me to debug different settings interactively and when working fullscreen I can control it from another system within the LAN.

One approach I've been looking at is to use an embedded HTTP server (http://en.wikipedia.org/wiki/Embedded_HTTP_server). This way I could just open a browser, connect to my software acting like a web server, see the current configuration, and change it with the click of a button. The problem is, web technology is as scary to me as shader assembly is to a web developer. :surrender

So does anyone have an idea how to get started with this? I'd really like to keep it lean (it only needs to serve one page to one user) but I'd rather not re-invent the wheel either (some people suggested to write my own server and generate the pages). If you know of any tools tailored towards my goal that would be awesome.

Thanks,

Nicolas

monjardin
01-22-2008, 10:52 AM
Actually, I've found embedding an HTTP server to be incredibly easy. I've used shttpd (http://shttpd.sourceforge.net/) in the past and it worked great. It's just a few C files and some callback functions to handle requests.

Nils mentioned a coworker doing an implementation from scratch in a day when I asked about the topic a few years ago (http://www.devmaster.net/forums/showthread.php?t=5776&highlight=shttpd).

I also made some Lua bindings to shttpd that really simplified the process. I used it for peeking/poking memory with a web browser in a running embedded system as well as for configuration. I used AJAX to get dynamic updates of some data too.

URL="http://www.keplerproject.org/"]Kepler[/URL] and Xavante (http://www.keplerproject.org/xavante/) may be worth looking into if you are found of Lua.

I'd encourage you to go this route. I did it to force myself to learn some web programming and found it beneficial.

Nick
01-23-2008, 01:48 AM
Thanks, I'll look at shttpd and Lua.

I'm still clueless how to make the "Hello World" case for this though. Even a page with one checkbox that controls a boolean in my C++ code would be an enormous breakthrough for me. Can anyone give me a hand with that or point me in the right direction of exactly what needs to be done? :worthy:

I think I can take it from that point, but I feel like a 13 year old newbie when it comes to seeing how the essential pieces fit together...

Moulinex
01-23-2008, 04:16 AM
Hi!

I made a simple HTTP server a few years ago just for fun, I'll see tonight (in about 12 hours from now)when I get home if I still have the code in the case nobody had already helped you in the mean time.

Moulinex

monjardin
01-23-2008, 07:41 AM
The following C program listing uses shttpd to serve a page with a checkbox and submit button that will set an internal boolean value:

#include <stdlib.h>
#include <string.h>

#include "shttpd.h"

enum BOOL { FALSE = 0, TRUE };
typedef enum BOOL BOOL;

static void
show_page(struct shttpd_arg *arg)
{
BOOL *data = arg->user_data;

/* create our simple page */
shttpd_printf(arg, "%s",
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"
"<html><body>");
shttpd_printf(arg, "<form method=\"GET\" action=\"/data\">"
"<input type=\"checkbox\" name=\"data\" %s/>"
"<input type=\"submit\"/>"
"</form>", *data ? "checked=\"1\"" : "");
shttpd_printf(arg, "%s", "</body></html>");

/*
* Tell shttpd that we are done (it would continue to callback for larger
* pages that don't fit in the output buffer)
*/
arg->flags |= SHTTPD_END_OF_OUTPUT;
}

static void
submit_data(struct shttpd_arg *arg)
{
BOOL *data = arg->user_data;
const char *query_string = shttpd_get_env(arg, "QUERY_STRING");

/* only checked boxes show up in the query string */
*data = (0 < strlen(query_string));

/* redisplay the page */
show_page(arg);
}

int
main(int argc, char *argv[])
{
struct shttpd_ctx *context = NULL;
BOOL data = FALSE; /* we'll set this boolean with a checkbox */

/* create an HTTP server */
context = shttpd_init(NULL, NULL);

/*
* Setup a callback for showing your page. It defaults to serving a page
* from the file system if you don't register the URI.
*/
shttpd_register_uri(context, "/", &show_page, (void *) &data);
shttpd_register_uri(context, "/index.html", &show_page, (void *) &data);

/*
* Setup a callback for checking our boolean value
*/
shttpd_register_uri(context, "/data", &submit_data, (void *) &data);

/* listen for connections on port 8080 */
(void) shttpd_listen(context, 8080, FALSE);

/* poll for connections */
for (;;) {
shttpd_poll(context, 1000);

if (data != prev_data) {
printf("data = %d\n", data);
prev_data = data;
}
}

/* cleanup */
shttpd_fini(context);

return EXIT_SUCCESS;
}

CheshireCat
01-23-2008, 10:54 AM
In couple of game projects I worked in, there was a C# GUI to control the game remotely. I don't know which protocol was used for the communication though.

monjardin
01-23-2008, 11:51 AM
Providing these controls from an embedded web server has the advantage of not requiring separate server and client applications to be kept synchronized.

karligula
01-23-2008, 12:09 PM
I've had a go at some web development using Visual Web Developer Express, it's fairly simple to get to grips with. You can do all the coding in c# and there are plenty of controls to develop good user interfaces with. It also uses the standard Visual Studio IDE, albeit with some minor alterations for web stuff.

Hope I'm answering the right question... ;-)

Moulinex
01-23-2008, 05:51 PM
Hi!

I made a simple HTTP server a few years ago just for fun, I'll see tonight (in about 12 hours from now)when I get home if I still have the code in the case nobody had already helped you in the mean time.

Moulinex

:blush: Sorry but I just can't find it...

Moulinex

Nick
01-24-2008, 05:33 AM
Thanks a lot monjardin! :yes: