Sign in to follow this  
lonewolff

Programming apps for web use

Recommended Posts

Hi, I program mainly in C++. Recently a need has arisen to write apps that can be accessed via a webpage. I am wondering how you go about programming and calling up this sort of app. Just say (as a test) I wanted to write a counter to read a file increment the contents and write the file back again (simple I know - but just a test to see how this all ties in). For example; int main() { //read the 'counter.txt' file here read'counter.txt';(pseudo) //convert the number in the file to an int (say int nCount) convert;(pseudo) nCount++; //Write file 'counter.txt' back again write'counter.txt';(pseudo) return 0; } How would I call this up in HTML everytime a webpage was accessed? This would have to reside and be run server side. Can this be done in a C++ and Java mix or do I need to know java or something? Thanks in advance!

Share this post


Link to post
Share on other sites
CGI.

As a side note, your code is not web-safe (if the first two users access the page at the same time, both will read 0, increment it, and write 1 back to the file). You might be interested in using database technologies (or any other ACID-supporting technology) to handle concurrency.

Share this post


Link to post
Share on other sites
That was just an example, though. But, I certainly get your point.

Just looked at you CGI link, thanks for that. So, is CGI something that needs to be installed or is it always there if you run a web server? I use IIS under Windows Server 2003.

How would you go about calling an app like this within HTML code?

Share this post


Link to post
Share on other sites
Quote:
Original post by lonewolffJust looked at you CGI link, thanks for that. So, is CGI something that needs to be installed or is it always there if you run a web server? I use IIS under Windows Server 2003.


You could look into best fit solution.

And then, there's this FastCGI, a recent release.

[Edited by - Antheus on October 10, 2007 7:03:57 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by lonewolff
That was just an example, though. But, I certainly get your point.

Just looked at you CGI link, thanks for that. So, is CGI something that needs to be installed or is it always there if you run a web server? I use IIS under Windows Server 2003.

How would you go about calling an app like this within HTML code?


CGI is just a way in which a web server can choose to run executables to generate data instead of returning static HTML pages. It's part of your web server's configuration.

HTML 'code' doesn't call applications. HTML is just a formatting language, sent from a web server to your client in order to render pages, and doesn't actually 'do' anything as such. To get the data from a CGI program, you simply point your browser at the URL that the CGI program is serving on, just like viewing a remote HTML file involves putting its URL in the browser. The server then runs the program and returns the output to your browser.

Share this post


Link to post
Share on other sites
What you do is to place your executable files under the directory on you server that is configured for binary files. If you use apache, for example, this would typically be "apache/cgi-bin/". Then when your browser accesses the web page or url that uses that programme, it executes and returns the result. For apache, you can find more on this subject here. Take care with these little programmes as (1) they can consume a lot of processor power on your server, and (2) they can be vulnerable to exploit by web hackers.

--random

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this