How do i call/send messages to a fastcgi app? - c++

I created a fastcgi app using this (threaded) example. I like it and the interface. I have the app running and have nginx using it with no problem. Now i would like to communicate with the fastcgi applications from my own C/C++ applications. What library may I use to communicate with the app?
When i google fastcgi and C++ i get results on writing fastcgi apps in C. I dont see any code to call apps using the fastcgi interface in C. My fastcgi app is running, theres no server on this machine and i'd like to talk to it as something like nginx does.

You basically need to implement Web server side of the FastCGI interface defined in this specification. It is biased towards writing a FastCGI application, but offers enough detail about the protocol to aid Web server side implementation, too.
See also this documentation and mod_fastcgi sources.
Note however, that depending on your end goal, it may be a better and considerably easier solution to use a lightweight HTTP server with FastCGI support like lighttpd (see this list for more) and issue ordinary HTTP requests to the server. The latter can easily be accomplished by using an HTTP client library (see for example this site).

Related

send array from c++ application to webApplication

i want to send one array from my Desktop application (c++) to another Web application(browser-based) which is written in javascript.
What is the standard approach to do this ?
my purpose just is to try send array through websocket to a simple web application.
i am a little familiar with node.js but i dont know is it possible to use it inside c++ application or not.
I want to send one array from my Desktop application (c++) to another Web application(browser-based) which is written in javascript. What is the standard approach to do this ?
Your question is too broad, or shows some misconceptions about desktop applications and web applications.
Be sure to understand (in details) HTTP and reason in terms of HTTP requests and responses (including those initiating a websocket connection). Remember that a websocket is above some HTTP connection.... Understand the role of HTTP cookies.
You could change your desktop application into a web application (perhaps running on http://localhost/ ...), but that requires some significant work and redesign. You probably then want to use some HTTP server library, like Wt or libonion (it supports Websockets).
Perhaps you might improve your web application to make AJAX requests (e.g. to some http://localhost:34567 ...) to you local application transformed into a specialized web sever running locally (and also using websockets, if you need that).
Perhaps you want your Desktop application to also become an HTTP client. You then need some HTTP client library (like libcurl or QtNetwork).

FastCGI Server C++

I am developing a server in C++, and I wanted to implement a FastCGI application that goes with it and handles the HTTP requests. I have looked at several examples of applications, but haven't seen anything about what I am supposed to do on the server side in order to communicate with the app.
Could anyone give me some insight on this? I have searched everywhere, even FastCGI website is down.
You can try fcgid, a very simple FastCGI Server implementation in C++. It's based on flup, a fastcgi server written in python.
Additionally, maybe digging into fastcgipp project can bring you some light. It's a FastCGI Client implementation. There are some good examples of use:
HelloWorld
Echo
Hope it helps.

Two way communication using AJAX from an HTML page to a C++ application running in same server

Is it possible to communicate from a web browser(Loaded an HTM page from server) to an application running in the same server using AJAX. Need to send the request from browser using a button click and update the page with responses received from one another application running in the same server machine?
I am using HTML pages to create website and not using any PHP or ASP like server side scripting. In server machine data are manipulated using a C++ application.
I think you can use any sort of Javascript functions to do that. But you might need to use jQuery or similar frameworks to make your live easier. You might need to search for "Comet Programming" to know exactly how to do 2-way communication between client and server
Updated:
Well, this kind of stuff requires you to read a lot (if you have not already known). Basically, what you need is a server that can do long-polling (or eventsource, websockets). There are many open-source ones that might help you to get started. I can list a several good ones here. There are a lot more
http://www.ape-project.org/
http://cometd.org/
http://socket.io/
http://code.google.com/p/erlycomet/
http://faye.jcoglan.com/
So after you have the comet server up and running you will need to setup the client side (probably Javascript). For those listed projects, most of them come with the client side code to interact with the server (Except for erlycomet). Therefore, you can just use the examples provided and run a quick prototype. If you want to use your raspberry pi, you can use nodejs which provide a lot of ease for dealing with real-time communication (socket.io, faye). And lately, http://www.meteor.com/
I would think of the problem this way: you want to provide a web front end to an existing c++ application. To achieve this you need to think about how your web server communicates with your c++ application. Communication between the browser and web server can be thought of as a separate problem - as you say AJAX calls can be used, or maybe have a look at websockets.
Once you have your request in the web server you need to communicate it to the C++ application (and/or visa versa). This can be done a number of ways, e.g. sockets or RPC. I found this question here which has some good advice.

Lightweight HTTP/HTTPS server in C++ (not C)

I need to build a lightweight http server for my application basically it's a server which listen to a port and outputs a status information on requests, https, other functionality. But I would like to know first if something like this existe in C++, for linux and open source.
Does anyone know a program like that?
Thanks.
EDIT: It should be able to support high load.
If you can use boost, the asio library provides an http example. It does not use SSL, but asio can use OpenSSL very easily.
If you want to handle high loads I would suggest following:
Use proper web server with all goodies it comes with like Lighttpd, Nginx or Apache (in that order).
It would do great job in serving static files and handle your application. And they are very lightweight.
Write an Application in C++ using proper web framework - CppCMS - that is designed for high loads
Connect Web Application to the server via FastCGI or SCGI protocol (in this order).
Disclaimer: I'm the author of CppCMS
A quick google search for "C++ web application framework" shows things called CppCMS and something else called WT. That might get you started.
Or, as Sam already answered: boost.asio comes with a HTTP example that may be sufficient if your needs are simple. (Real HTTP request handling is actually surprisingly complex: http://webmachine.basho.com/diagram.html )
See thttpd. Supposibly the fastest open source file server on all machines with a single CPU.
If not using HTTPS, it's about a two hour exercise to write a static file server.

Using C++/Qt4 application as backend for web application

for one of my applications I'd like to provide a minimal web interface. This core application is written in C++ and uses Qt4 as a framework. Since I'm also using some libraries I wrote to calculate some things and do some complex data management, I'd like to use this existing code as a backend to the web interface.
Idea 1: Using an embedded web server
The first thing I tried (and which worked to some degree) was using an embedded web server (mongoose). As you can imagine, it is just a very thin library and you have to implement a lot of things yourself (like session management, cookies, etc.).
Idea 2: Using a normal web server and adding a fcgi/cgi/scgi backend to my application
The next thing that came to my head was using a mature but compact web server (for instance, lighttpd) and simple provide a fcgi/scgi/cgi backend to it. I could write the web application using a good framework, like Pylons, PHP, or RoR, (...) and simply have an URL prefix, like /a/... which allows me to directly talk to the backend.
I tried to implement the libfcgi into my application, but it looks messier than needed (for instance you'd have to implement your own TCP/IP sockets to pass on data between your app and the web server and tunnel it through the FCGI library, meh)
Idea 3: Creating a command line version of my application which does the most basic things and use a normal web server and framework to do the rest
This is the third idea that came to my head. It is basically about creating a web application using a traditional way (PHP, RoR, etc.) and using a command line version of my application to process data and return it when needed.
I've got some experience with creating web applications, but I never had to do something like this, so I'd like to hear some ideas or suggestions. I'd like to use JavaScript on the browsers (AJAX, that is) and pass some JSON constructs between web browser and server to make the user experience a bit smoother.
So what are your suggestions, ideas on this? I don't want to re-invent the wheel, honestly.
I would never expose a custom written application to the net as front-end, for that servers like apache or lighthttp are build. They give you some serious security out of the box.
As for interaction of your app with that webserver, it depends a bit on the load and what kind of experience you have with writing software in PHP, python or other languages supported by your web server (via interpreter of course).
A slight load, and a command line tool accessed from PHP might do perfectly well.
A more heavy load and you might wish to implement a simple (SOAP?) server with Qt and access that from a python (or php) script.
That way you don't need to do layout in you app, and you also don't need to implement security all that much.
I'm currently researching a similar situation (custom web app backend using Qt), and the least bad option is FastCGI. Found something you might be interested in. Not production ready without some serious testing, but this might be a good starting point for Qt - FastCGI interop: FastCGIQt
I've used the FastCGI Protocol Driver library for a similar project (also a Qt application), the download link is at the end of that page [Libfastcgi]. Integration with the application turned out actually comparatively easy. Lighttpd + mod_fastcgi was used as web server. Can't say anything about FastCGIQt, though.
You Wt works well to provide a web interface to Qt based applications. Both have a similar programming style, and there's an example that demonstrates the integration with Qt.
Here is example of embedded QML-server: https://github.com/ncp1402/ql-server