Unable to put a simulation in C to a webpage

I have the following simulation in C for cars in a traffic circle alt text http://dl.getdropbox.com/u/175564/cars.png

For example,

7 <space> <enter>

gives more cars to the simulation, while

s1 <enter>

puts a top sign to the incoming road #1.

I want to put the simulation to an internet page such that users can try it. However, I do not know where I should start.

I know Joomla and little about Django. Perhaps, they can be useful.

How can you put a C program to a Webpage such that users can use it?

Upvotes: 3

Views: 243

Answers (7)

KarlP
KarlP

Reputation: 5181

If you want a dynamic simulation, where the cars moves while you watch , you'll need an applet or flash.

A cgi program renders the page on each http GET/POST (on reload, submit etc) and that is probably not what you want.

Upvotes: 2

user50049
user50049

Reputation:

I would recommend going with sockets. If your C program could set up and listen on a local or internet socket, you could use the socket facilities in any language to send it arguments and get output.

If that's going to be too much of a pain, have php exec the program while directing the output to some file. Then, have php read that file.

Looking at the output of your program, I think trying to print the results of shell_exec() will result in clobbered output.

So, you could shell_exec("/bin/program -arguments > /tmp/prog-tmp.txt") , then read prog-tmp.txt.

Upvotes: 1

sean riley
sean riley

Reputation: 2743

You could run the C code in a flash app using alchemy:

http://labs.adobe.com/technologies/alchemy/

Upvotes: 4

Alex S
Alex S

Reputation: 26071

I assume the C program needs input while it's running and not via command-line arguments? If I'm wrong, you can just use PHP and shell_exec() to run the program. The function returns anything printed to stdout.

Such a page might look like:


    $sim = shell_exec("/path/to/binary -a 5 -b 6");
    echo $sim;

Where the string passed to shell_exec is exactly what you'd type on the command line.

Upvotes: 2

splicer
splicer

Reputation: 5394

Here's a good intro to writing CGIs in C: http://www.cs.tut.fi/~jkorpela/forms/cgic.html

However, since you're a beginner, I'd recommend porting your program to PHP. It's a very easy language to pick up, and it's a much easier route than writing a CGI in C.

Upvotes: 2

Robert Massaioli
Robert Massaioli

Reputation: 13487

CGI is what you want; it will let you embed any program you want into a website, it was made for that purpose. Then perhaps embedding a few more options with PHP and HTML will let the user acutally input data into the program via the web. It should not be too hard.

Take a look here for more info: http://www.cs.tut.fi/~jkorpela/perl/cgi.html

I think that is a good pointer in the right direction. I hope that helps.

Upvotes: 4

Shane C. Mason
Shane C. Mason

Reputation: 7615

I would start with a flash or java applet wrapper. You can communicate with your application over a tcp connection and display the results in the flash or applet.

Upvotes: 1

Related Questions