The web is playing an increasingly important role for desktop software. Developers often need to interact with a web server for tasks like; installation, authentication, application updates, data transfer, error reporting and secure transactions for billing. Typically these applications use HTTP and port 80 to avoid firewall support issues.
FastCGI provides a standard protocol for many servers including Windows IIS and Linux Apache, and most web development languages like php, Java, Perl, Ruby, Python etc for developing applications that execute on the server side. However, FastCGI applications may also be written in the same powerful high level languages (Basic/C/C++) used to create the desktop software, making code instantly reusable on the server side.
While Java/Javascript and .NET tend to dominate the web capable application development space these days, both have disadvantages for high performance desktop software. As an interpreted language with issues, JavaScript is not ideal, and .NET's 'managed code' and reliance on COM to wrap API's often leads to speed and reliability issues. FastCGI provides a powerful alternative protocol, supported by most servers and languages, that integrates into a development project quickly and easily.
The presentation will touch on the HTTP protocol in general, the WinHTTP library and reasons for choosing the flat API over the COM interface, the concept of the FastCGI protocol, FastCGI vs CGI and how it has evolved recently. I will then show you how to write, deploy and test a FastCGI application on your laptop in two minutes using a powerful free web server - see my Blog for more details http://mbbz.blogspot.com
2. Development Considerations Fast to develop Same language Same code at each end Reliable Scalable Zero Configuration (Ports, Firewalls etc) No additional support load
41. Hello World in BASIC #INCLUDE "FCGX_Header.bas" FUNCTION WINMAIN LOCAL Count AS LONG LOCAL sReplyASSTRING LOCAL FCGXReq AS FCGX_REQUEST '// FCGX Structure '// Open Databases CALL FCGX_InitRequest(VARPTR(FCGXReq), 0, 0) DO '// Main Request processing loop INCR Count IF FCGX_Accept_r(VARPTR(FCGXReq)) < 0 THEN EXIT LOOP '//Execution blocked until HTTP request arrives sReply = "Content-Type: text/html"+$CRLF+$CRLF '// The reply begins with a valid HTTP header sReply = sReply + “Hello World, Count=" + STR$(Count) FCGX_PutStr( STRPTR(sReply), LEN(sReply), FCGXReq.pOut ) LOOP '// Close Databases etc here END FUNCTION
42. Hello World in C++ #include <libfcgi2.h> int main( ) { FCGX_REQUEST req = {0}; int count(0); string sReply ; ostringstreamss; FCGX_InitRequest( &req, 0, 0 ); // Open Database while (true) { if( FCGX_Accept_r(&req) < 0 ) break; // Execution is blocked until a Request is received count++; ss << count; // typesafe conversion sReply = "Content-Type: text/html Hello World" + ss.str(); FCGX_PutStr( sReply.data(), sReply.length(), req.pOut) ; ss.str(""); // clear the string stream object } // Close Database return 0; }
50. SQL requests can generate large responses! XML introduces severe bloat An example framework for interacting with a database on a server - Chunks - Encryption/Compression - Binary Data Chunk Protocol: HEADER DATA BODY STRINGS Remote SQL