9

I was wondering what would be the best method for creating a web end for interfacing with a C++ program on the server. At first I simply thought just using shell execution from the web server side language (like shell_exec() in PHP), but I was wondering if there is a "better" way. Maybe something more native or is this a bad practice for some reason?

2
  • Should be on stackoverflow not here AFAIK. Might be wrong though.
    – Guillaume
    Commented Apr 2, 2011 at 4:39
  • 4
    I figured it would be better on programmers.SE because it is more theoretical and doesn't really require a code based answer. This is more based on the ideas surrounding achieving this task, not an exact method of how to do it.
    – Ben
    Commented Apr 2, 2011 at 4:46

3 Answers 3

7

Web programming with C++ has pretty much gone out of style. The traditional way to do it was with CGI. See here for a tutorial.

Or you can add an embedded webserver like mongoose

However, I think it's easiest to use PHP's passthru. For example, on one of my sites I have a C++ program that generates images, to display the images I do:

<?

header("content-type: image/png"); 

$temp = $_GET["temp"];
$rain = $_GET["rain"];

passthru("/home/rrabien/marker $temp $rain")

?>
3
  • This looks pretty good to me, thanks for the passthru function. I had never heard of that one. All in all this is what I had originally had in mind, but its good to know that this is really the best way to achieve what I desired. Thanks FigBug.
    – Ben
    Commented Apr 2, 2011 at 5:41
  • Do NOT use passthru without correctly escaping input, or you're asking to be hacked. Read this link: acunetix.com/websitesecurity/php-security-1.htm Commented Apr 3, 2011 at 18:18
  • This is how I do it, but I use django. Instead of passing through to the c++ application directly, I have a python wrapper for either launching my c++ app, or communicating through IPC or network with a daemon using some internal api.Works really well. Commented Apr 4, 2011 at 18:57
3

Wt, the C++ web toolkit is a library with a set of classes that make it much easier to add a web interface of any complexity to a C++ program. It focuses on the web interface aspects only, and is otherwise non-intrusive to your program.

1

I'm sure there are compilable web framework out there for C/C++. However, I'm not familiar with any.

What I am familiar with is the ease of which you can extend Python with C/C++. I believe it can be made even simpler by using SWiG. Given that Python has a plethora of web frameworks this may be an option for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.