Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
Should be on stackoverflow not here AFAIK. Might be wrong though. –  Enders Apr 2 '11 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 Apr 2 '11 at 4:46

3 Answers 3

up vote 7 down vote accepted

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")

?>
share|improve this answer
    
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 Apr 2 '11 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 –  Joeri Sebrechts Apr 3 '11 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. –  michalmocny Apr 4 '11 at 18:57

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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