I want to use AWS products to build some application on it. For now, i want to test this -
1) Create a webpage hosted at AWS with a simple text box and a submit button, for checking if a number is prime.
2) Compile a C++ program on EC2 to accept a number and reply if it is prime.
Can someone list the steps involved in doing this?
(The above example mirrors simplistically the actual application that i have in mind, with a http frontend and a c++ backend)
If you use the default Linux AMI, you will gave a standard Apache installation ready to go. It sounds like the invocation style of your app is request-response, so at least to begin with, you could just use CGI to get Apache to run your app.
To achieve this, you would do something like this:
Create a static html page with a form and a submit button which passes the form data to your app via CGI
Install your app into an appropriate directory (see the Apache config for details) to run it via CGI, taking care to ensure the correct permissions are set
Have your app parse the CGI environment variables to gather the input
Perform the processing required
Generate the resulting output as an HTTP response (to get started, just use text/plain).
Please note that there are many security issues to keep in mind here, so it is very important to perform strict validation on all data supplied by the web user for escaping issues, buffer overflows and so on.
If you aren't familiar with the above, you will need to read up on HTML forms, Apache configuration and basic HTTP headers at at minimum. There are plenty of examples out there, and some great books covering the topic.
To this end, various libraries have been developed to facilitate this:
Which C++ Library for CGI Programming?
There are also many other options for interfacing your app with Apache, such as FastCGI.
Related
I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).
I have some experience with php / python programming and i am curious to know how actually servers like apache / light httpd gives data to the script?
Can it be bypassed to a c/c++ program ? and handled via that?
Sorry for this kinds of question. I am too much curious. Googled it but can not find a really good answer.
Today, probably the most used and with less overhead is SAPI:
http://en.wikipedia.org/wiki/Server_Application_Programming_Interface
Some examples of SAPI is ISAPI that is mostly for IIS, Apache modules for Apache,
and the list extends with Servers.
ISAPI:
Uses a system dynamic linked library (DLL) so it "attach" to the webserver and functions
can be called direct on it.
http://en.wikipedia.org/wiki/Internet_Server_Application_Programming_Interface
CGI: http://www.w3.org/CGI/
normally a new process is created for each request, the data from the server is normally passed in stdin and the program writes to stdout, some information is passed as environment variables.
FastCGI: http://www.fastcgi.com/drupal/
As the name suggest, its like CGI but does not need to run the program every time a request is made, being faster and using less resources.
Xitami have their own too, called LRWP http://legacy.imatix.com/html/xitami/index12.htm
But each server can implement their own.
Note: The module or external program is what parses the script. The SAPI, CGI, FastCGI and whatever will integrate with the interpreter of the script, a binary. The interpreter then receive the request path, find the script file, and parse it.
Ex: PHP has its apache and IIS modules.
These things follow a request-response pattern where a request is made to a web server. The web server will process the request and execute any server side code (script) associated with the url that the request resolves to (web service or web page typically). The script will execute and result in a response that is sent back to the caller.
There is so much power at the command line. Web pages are for non-power-users. I'd like my Django app to also have a console-based interface so that people can really work fast and not fiddle with graphics and a mouse. Has anyone tried doing something like this using Django? I like the example of heroku -- once you create an account at heroku.com you can do so much at the command line and interact with the server without the overhead of HTTP.
This is exactly what the 'shell' command of manage.py does. It gives you a python prompt with a few things set up so you can import your models and mess with them via the django API. So if your command-line tools are for superusers with shell access on the server then you can just write some python scripts that get run in the same way.
However, if you want access to users from other machines then you (obviously?) need to go via HTTP, but python has libraries for doing http requests. The only complication is with logins and cookies, but python's libraries can help you with that too - see urllib2, cookielib etc. You'd have to write some plain-text templates for the returned output.
I have no experience with heroku so I'm not sure what it's doing - what kind of thing can you do at the command line with it?
I am looking on advice on how best to approach a new project I need to develop. From the outset I must add, I have 0 experience with Web development on any level.
What I need to do is provide a web interface through the browser which will communicate with a server back end. The data retrieved will be sourced from either a DB or from another source - external device which the server itself will communicate with via IP. The data retrieved from the external device will always be a string format of n length (non unicode) and the DB data will mostly be strings and numbers with the odd blob thrown in (storing a picture). The communication will always go from the Client (web browser) to the Server. I don't believe that the server would need to instigate the comms.
I have Delphi XE, so started looking at using a REST server for communication and I think that seems to be OK. However, from what I can see, I need to create HTML web pages to "render" the data on the web browser. Is that true? Can I use the IW components with a REST server? If so, I'm not sure how to get the data to/from the browser UI. Am I better of investigating Ruby on Rails perhaps? From what I read on a different thread in here, it's based on MVC and some other areas which I feel, design wise, would fit how I would create the application (I was planning on creating the app based on the MVP or similar design pattern).
I think REST makes the most sense, so if the IW components can't be used, are there any 3rd party products I can use which would let me design "pretty" UI html. Given I don't know java script, would that be a stumbling block with REST too.
Thanks and hopefully I have provided enough information.
Thanks
Jason
Will a human being be responsible for typing the data retrieved from your external device into a web page?
If so, and you have no web development experience, Intraweb is definitely the way to go for Delphi programmers wanting to build a web application without learning new skills. For additional components to create a prettier UI I suggest using TMS Software's Intraweb Component Pack Pro.
If you don't need a human being to manually type in this data then you don't need Intraweb at all. Instead you would write a client application which presumably interrogated your external device for the data and then transmitted it to the REST server. Look at the documentation you've used to build your REST server and it should have a section on how to build a REST client.
You can build an ISAPI module with delphi that does the job, or include a HTTP server right into you executable with Indy, ICS or Synapse.
ISAPI will give you the freedom to choose Apache or IIS and give you all their power this way. Embeded HTTP server will give you a nice small application in which you control all ascpects of how it works.
Yes go with REST as it is simple and clean. All you need is to think and design the API (functions that your server will support). You can bind the APIs to the URL schema thus using the REST principle. I would do it simply like this.
A client makes a request. You show some form of GUI (load or render a HTML page with possible javascript)
User makes an action, you call appropriate API (or the user does it directly).
Show the user some result
Just guide the user process through a series of API calls until the result is made
You can use plain HTML and then add javascript if needed (jquery) or you can use ExtJS from Sencha which makes building a nice GUI a lot easier and is very well structured.
I would not use any "WYSIWYG" web tools. Plain old HTML written by your favorite editor is still the king in my opinion.
I am trying to create simple flex application, which uses django as a back-end part. Have a question:
Usually when I run my application Flex Builder creates a file in a directory on my local PC and then opens a browser and points to it. Everything was fine, but when I decided to link django server to flex applications via xml data providers I started to get security errors. (Related to absence of crossdomain.xml). When I created the file and put it on the server:
<?xml version="1.0"?>
<!-- http://www.foo.com/crossdomain.xml -->
<cross-domain-policy>
<allow-access-from domain="http://127.0.0.1:8000"/>
<allow-access-from domain="127.0.0.1"/>
</cross-domain-policy>
Then tried the application again, I got error in console of my FB Error: Request for resource at http://127.0.0.1:8000/go/active/ by requestor from file:///Users/oleg/Documents/FB3/usersList/bin-debug/usersList.swf is denied due to lack of policy file permissions.
I don't know how to fix the error. But also the question is there a way to configure FB3 to put my swf files to the server directly, so I will not need any crossdomain?
Thanks
Oleg
We struggled with this a lot. The Flex security stuff didn't strike me as well built, but perhaps we just had different approaches in mind than Adobe's developers. The solution that worked for us was to serve both the SWF and the dynamic data from the same host and port.
On our development boxes, we tell Apache to serve the SWF from a directory in the workspace, and the dynamic data from a local copy of the app. When we push to production, SWF and app get pushed simultaneously to the same virtual host.
If that's inconvenient for you, the Apache ProxyPass directive can be used to make Apache front for other servers. I've not used that in production, but it's been very handy for developer setups.
I don't know a way to get FlexBuilder to automatically deploy your changed SWF; you could certainly look into an automation approach (like Maven and Flex-Mojos) to make that happen.
That said, getting rid of that error is usually just a matter of adding a policy file to the server.
The second error is caused because you're trying to fetch http resources from a "file" location. My recommendation is that you change your Flex Builder project so it outputs to a location within the Django web site, rather than to the flex-bin directory. This setting can be changed in the properties dialog of the project. Then, you should be able to have your front-end and back-end share the same protocol and domain.