views:

61

answers:

3

Hi,

I am currently having an idea where I want to save an image from a c++/openGL application on demand from a browser. So basically I would like to run the application itself on the server and have a simple communication layer like this:

JS -> tell application to do calculations (and maybe pass a string or some simple data) application -> tell JS when finished and maybe send a link, text or something as simple as that.

I don't really have alot of experience with webservers and as such don't know if that is possible at all (it's just my naive thinking). And note: I am not talking about a webGL application, I just want to have simple communication between a c++ serverside application, and the user.

Any ideas how to do that?

Thanks alot!

A: 

Basically no matter what your language/framework you choose for your web server, you just need a interface that is callable from your browser JS, and you can do whatever you want in the server once it recieves the call.

Most likely any web service interface exposed from the server.

Just need to safeguard your server not to get DoS since it sounds like it's a huge process.

Timothy Chen
well, I don't want to write a webserver from scratch, isn't there a way to make a c++ app accessible from let's say an apache web server?
moka
A: 

Well you could always use the cgi interface to invoke your application and have it save that image somewhere accessible to the webserver. Then have your js load that via ajax. Or make a cgi App that talks to the app and then serves a small page with the pic in it.

[EDIT] Answering the comments: CGI is not complex to learn, it is mostly a simple convention you can follow. I think it would give you the maximum of flexibility. I don't know which php mods allow you to leave the cozy protection of the server-application and interact with other stuff on your server.

AndreasT
hey, I don't know CGI, but since I know some PHP, would that be an option too?
moka
php serves images nicely, you need to find something that passes the request to the application though. If your application just has to be started once and then stops once it has created the image you should follow Elrohir's advice. Haven't tried that though. If it keeps running and has to be handed the request somehow. There's a ton of possibilities to do that, only a few of them elegant. We would need more info about the application. Does it run only once or does it keep running. Does it do the picture output itself or do you need some intermediate framegrabber...
AndreasT
A: 

As far as I know, JavaScript (at least when embedded in HTML) is executed on your local machine and not on the server so that there is IMHO no way to directly start your server-application using JS.

PHP for example is executed on the server-side and so you could use e.g. the php system function to call your C++/OpenGL application on the server - initiated on demand through a web-browser. When the call is finished you could then directly present the image.

Elrohir
ah, good point! I know some PHP too, so the question is how I can make a c++ application accessible to PHP.
moka
Do you know the system function? -> http://php.net/manual/en/function.system.php. Or passthru() -> http://www.php.net/manual/en/function.passthru.phpYour C++-App could save the image in a temp-dir and return the path to it. The php-skript would then easily do the system() call and then something like this: echo "<img href=". $return . ">";
Elrohir
okay, can I simply place a commandline c++ app on a apache webserver? Thanks!
moka
that depends on how you can access the server. is it a linux/unix server? are you allowed to execute files there?
Elrohir