Reputation: 2851
I am developing a prototype web application. I am using a toy http server which I have developed myself and it is written in C. The server needs to obtain text data from html form submitted and for furthur processing should pass it to a script which I have written in python. I know the following methods to achieve the same. Also once the processing is done the script has to return the data to server.
Normally this is abstracted out as most people use apache or nginx as theor service. How can CGI be achieved in Server code?
Upvotes: 0
Views: 114
Reputation: 3701
CGI is covered here: https://www.rfc-editor.org/rfc/rfc3875
By 'CGI over sockets' you probably mean FastCGI which is a bit different (and involves a long running process listening on a Unix socket and sending back responses). Classical CGI involves spawning a short lived process which then receives the request parameters via environment variables (set this from your server via setenv()
.
Request data is sent to the spawned process via stdin (e.g. in Python, sys.stdin
). The output response is then written (with headers and all) via stdout.
CGI is very simple and this is why it was so quick to be adopted by a high number of languages -- the learning curve to implementing CGI was rather quick.
FastCGI is similar to CGI only at the script language layer (i.e. the programming interface remains somewhat similar); however the actual mechanics are rather different (you need to serialize the information over Unix sockets).
Upvotes: 1