I've inherited a web application that is running a CherryPy web server. I need to implement a user interface that will automatically update with data from the server. Right now the solution is to use JavaScript polling. While it works, it feels dirty.
I would love to use Socket.IO, but I cannot find any support for doing this with a CherryPy backend. Does any one have any insight into this approach?
WebSockets would be great too, except for the need to support IE. Are there any non-Flash fallbacks for IE? And as for WebSocket support in CherryPy I have found ws4py, but I don't know have any experience using it.
Are there any Comet implementations for CherryPy.
For what it's worth I have been scouring the internet the last few days looking for solutions, but I really haven't found any "this is exactly what you can do" results.
Is it possible and does it make any sense to install Node.JS and have the client UI communicate with the Node.JS server which that talks to CherryPy? Or is that just wasteful?
Thanks!
This is exactly what you can do - In order to easily publish real-time data to your web-client user to send asynchronous updates, you would do the following.
pip install cherrypy
pip install pubnub
import cherrypy
from Pubnub import Pubnub
pubnub = Pubnub( "demo", "demo" )
class HelloWorld(object):
def index(self):
## Put the following line where in place when you want to send
## the Push Signal to your Web User.
pubnub.publish({
"channel" : "cherryPy_example", ## CHANNEL NAME
"message" : "hi!"
})
## If you want to return the Details.
return "Message Sent"
index.exposed = True
Next, Paste the following code into your Web HTML/JavaScript Page:
<script src="https://pubnub.a.ssl.fastly.net/pubnub-3.4.3.min.js"></script>
<script>(function(){
var pubnub = PUBNUB.init({
subscribe_key : 'demo',
ssl : true
});
pubnub.subscribe({
channel : 'cherryPy_example', // CHANNEL NAME
message : function(message) {
alert(JSON.stringify(message));
}
});
})();</script>
Learn more details here for the Python PubNub lib - https://github.com/pubnub/pubnub-api/tree/master/python#you-must-have-a-pubnub-account-to-use-the-api
Important note: This is for a free version. The Python lib is not secure in the free version. I reocmmend you setup a paid version of this account by visiting: https://admin.pubnub.com/ and setting up a secured Python PIP Lib replacing the "demo" key settings with the provided secure secret keys.