Can Azure Websites host Twisted applications? e.g. something like:
from twisted.internet import reactor
from twisted.web import server
site = server.Site(myresource)
reactor.listenTCP(80, site)
reactor.run()
From http://azure.microsoft.com/en-us/documentation/articles/web-sites-python-configure/ it sounds like only WSGI apps are supported, but just wanted to confirm from an Azure Websites expert that there's no way to directly run something like the above.
--
This excerpt from discussion with Glyph (Twisted author) in the #twisted.web IRC channel covers the Twisted half of this question:
16:53:28 glyph: twisted has a WSGI _container_
16:53:34 glyph: twisted _is not_ a WSGI application
16:53:36 glyph: in any part
16:53:43 glyph: so you can't make twisted into a WSGI app
16:53:55 glyph: you can maybe invoke some Twisted code _from_ a WSGI app
16:54:05 glyph: but what that example is doing is speaking HTTP, and WSGI applications have to speak WSGI, they are not allowed to speak HTTP directly.
16:56:47 tos9: crochet?
16:56:56 glyph: tos9: crochet can't eat the inbound HTTP socket
16:56:58 glyph: tos9: so it doesn't help
16:57:11 glyph: you could write a thing that did the _outgoing_ traffic with Twisted, but since you can't handle the inbound request, you're bummed
16:57:37 glyph: basically Twisted's job is doing network I/O and if you're inside a WSGI stack, someone else is already doing the job of doing the network I/O
If there is in fact no way to directly run something like this, it seems like choosing a language other than Python buys you more flexibility on Azure Websites. For example, from http://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/ it looks like you can host a Node app on Azure Websites which speaks HTTP directly. Confirmations or corrections gratefully received.
Please check https://social.msdn.microsoft.com/Forums/en-US/ed1c80c4-4621-4d02-8902-6ecc1166ac8c/running-twisted-on-azure-websites?forum=windowsazurewebsitesprevie&prof=required for answer.
As you described in Running Twisted on Azure Websites .
What you said is right. For node.js, you can host a Node app on Azure Websites which speaks HTTP directly. Please refer to http://blogs.msdn.com/b/hanuk/archive/2012/05/05/top-benefits-of-running-node-js-on-windows-azure.aspx
For Python, there's no direct way run twiisted code via http.
Yes, it can. Their main page says
Azure supports any operating system, language, tool, and framework— from Windows to Linux, SQL Server to Oracle, C# to Java.
The page you referenced shows a basic template - it is an example of how to set up a particular WSGI application. You don't have to do it this way.
You can setup a virtual machine and put anything you like on it.
If Twisted doesn't require any specific binaries to be installed (no registry keys, hard coded path requirements, etc) then you can just copy the relevant binaries over with your website and invoke those bits instead.
Related
I created an api using SLIM framework, but the services are not accessible to public as they are limited to localhost. how to host the services on a realtime server, so that, they can be accessible from anywhere?
please some one help me
This question requires more detail in order to answer properly.
If you are hosting your API on a windows server, then it is likely you have configured some kind of "WAMP" stack, correct? Or maybe serving PHP through IIS? This are important questions because we need to know what port you have bound your web application server to, which leads us to the next question...
Where are you hosting the server which is running the application which bound to what port?
Ultimately, a public, external IP will need to be either:
a. NAT'ed to the internal IP of your web server instanced
b. Port-forwarded to the internal IP of the server running your web application
Still, we are making a lot of assumptions here because getting a web application "accessible from anywhere" will require different work depending on your environment.
Here is the most basic example:
You are at home, running this API on your Windows workstation and will like to be able to hit it from a remote location.
Ensure Windows firewall allows inbound traffic to the port on which your application is running (probably port 80/HTTP, maybe 443/HTTPS).
Log into your ISP's router and configure port-forwarding to ensure inbound traffic on, say, port 80, is routed to the internal IP of the workstation running the API.
That's all there is to it.
Keep in mind that this also assumes that your ISP even allows you to expose your own web server to the internet on port 80 (or 443). Also, since we know nothing about your environment, this is all pure conjecture. Please provide more information you would like a real answer.
The most traditional way to host Slim Framework, would be through Apache. Install Apache and be sure you have the proper network settings to allow inbound connections, but more information about your setup could be needed for proper guidance.
http://httpd.apache.org/docs/2.4/platform/windows.html
When Apache is installed and working, you need to set Rewrite rules on the URL, information on that can be found on http://docs.slimframework.com/routing/rewrite/.
Your question on the verge of off topic, it probaly is, but read up on what questions can be asked and not, here on Stackoverflow, hope i could help.
Doesn't have to be Apache, but that's just the only HTTP server I know of (Actually could you guys recommend alternatives that I could look into as well?)
Anyways, so I have been messing around with Amazon Web Services and I created an EC2 server instance with an Amazon Linux Image. On that, (Following guides and examples) I installed Apache and now when I make a GET request to my public IP, it returns to me the HTML files I created on my server.
My question is, what if I never installed Apache, and then made an HTTP request to my public IP? For no reason really, the question just came up in my head and I'm curious. I'd rather not figure out how to uninstall Apache or create a new instance to figure it out, so I was wondering if somebody could weigh in as well as tell me a little more about what it is exactly apache does on a server. My understanding is that it is a layer you can install on your server OS that will create a socket listener to port 80 (HTTP), and when a request is made on that port, Apache will return web pages? Also I think I read somewhere you could configure Apache to forward a port to something like a python server script?
Thanks in advance for your time!
could you guys recommend alternatives that I could look into as well?)
nginx is a popular alternative to apache. It's much more efficient.
what if I never installed Apache, and then made an HTTP request to my public IP?
Your browser would get a "connection reset" because there is nothing on port 80. Your browser would display a message (Chrome says "This webpage is not available"). You would NOT get a "404" because that requires an HTTP server to send HTTP codes.
If your server was firewalled instead, you'd bet a busy wait for a while, then a message about the server not responding.
Also I think I read somewhere you could configure Apache to forward a port to something like a python server script?
Yes, that is called "reverse proxy" mode. It's essential to any application website if you want to scale. The web server(s) can distribute traffic to one or more backends running the application. The web server is useful for filtering bad requests (since your backend in Ruby/Python will be 1000's of times slower than the reverse proxy.)
Well, if you want to test what will happen if Apache isn't installed, you can always just stop the Apache service by typing:
sudo service apache2 stop
or
sudo service httpd stop
depending on your version. Then if you visit your site's webpage you'll get a 404 error or something similar.
There are ways to use python scripts to run simple servers, but in general it's easier to just let Apache handle that and use a framework like Ruby on Rails or Django to control the display and creation of content for your server.
I want to write a small back-end REST server using Play! Framework 2.1.3. This server will only serve WS requests, and all communication to it must be made over SSL. For this reason, I don't want to have an HTTP port open for this server at all.
I've seen this question regarding SSL on various Play! branches, and according to the linked discussion, the only way to open SSL port (which worked for me) is to add JAVA_OPTS before running the server, like so:
JAVA_OPTS=-Dhttps.port=9443 play run
This setting opens both HTTP and HTTPS ports for communication.
My questions are:
Is it possible to open the server only for SSL communication? How?
Is there a configuration file where I put this setting?
Thanks!
This is super easy with Play 2.2, not sure it works on 2.1.3, I didn't see it in the 2.1.x docs...but was in the 2.2.x docs...so give it a shot, it might be implemented.
Throw this in your configuration file :
http.port=disabled
Or you could run it with the command line option :
-Dhttp.port=disabled
http://www.playframework.com/documentation/2.2.x/ConfiguringHttps
I want to make an app that displays new data whenever they arrive inside a folder via xml. I want to use html5 web sockets but I am confused on how it should be done. I am using xaamp on my machine for development. Do I have to install another server to use websockets? Is apache as it is compatible and if yes how do I make the connection with the client. Thank you in advance..
Your options are:
Use something like mod_websocket, as pointed out by Phillip Kovalev. Or pywebsocket. You could also try PHP WebSocket.
Use a dedicated self-hosted realtime web technology for realtime communication between server and client. If you do this you'll also need to define a way of application to realtime web server communications - normally achieved through message queues.
Use a hosted realtime web solution and offload the realtime push aspect of your application.
There are concerns about using Apache with this type of technology since this technology maintains long-running persistent connections between the server and client and Apache isn't know to be too great at this. So, the best solution may be to:
Go with a 2nd dedicated realtime web server in conjunction with using Apache as your application server
Use a self-hosted realtime web server that has the ability to handle many concurrent connections
Use a hosted service along with your Apache application server.
If you don't expect many concurrent connections or if you are just trying out the technology then it's possible that Apache alone will be all you need.
Look at mod_websocket. It supports latest and commonly implemented by browsers vendors protocol version.
What does it mean when we say an application can run in CGI mode? I was reviewing the features of various CMS systems on cmsmatrix.org and "CGI mode support" was listed as a feature. What are the other "modes" in which a web application can run?
Basically, CGI implies that the webserver will execute an external process, get its result (a generated HTML page, an image, ...) and send it back to the client.
This has major drawbacks because it launchs the external process each time it is needed, so this can be a big overhead.
You have also FastCGI that launch the external process once, and reuses it when needed.
But usually, languages are integrated directly in the webserver.
For example, Apache has a mod_perl module to execute perl scripts, instead of executing perl scripts via CGI
CGI stands for 'Common Gateway Interface', which is an old architecture for web applications. CGI works by placing the variables from the HTTP request and fork/exec()ing the CGI process. It gained popularity in the early days of web development as it worked well on a unix host. Perl/CGI was a popular architecture in this era and it contributed substantially to the popularity of Perl as a language.
The main claim to fame of CGI is that it doesn't require much plumbing, so it will work with most web servers. The main drawback is that the fork-exec process is slow-ish as the CGI script has to be started (which may involve starting a perl or other interpreter). On Windows, spawning a new process is much slower than unix, so CGI is even more inefficient.
CGI is a protocol that is used by web servers to call executable files on the server. Upon receiving a request, it sends the information about the request to the cgi script and returns the result of that script back to the browser.
An alternative to that is fastcgi. This means, that the web server does not contact a script to answer the request, but a process. The communication protocol is still the same, though (hence the name).