diff options
Diffstat (limited to 'python-tornado')
| -rw-r--r-- | python-tornado/README | 92 |
1 files changed, 31 insertions, 61 deletions
diff --git a/python-tornado/README b/python-tornado/README index d6eeebe..e046c6b 100644 --- a/python-tornado/README +++ b/python-tornado/README @@ -6,7 +6,7 @@ ## ---------------------------------------------------- ## ---------------------------------------------------- -## PubNub 3.1 Real-time Cloud Push API - PYTHON TORNADO +## PubNub 3.5.0 Real-time Cloud Push API - PYTHON TORNADO ## ---------------------------------------------------- ## ## www.pubnub.com - PubNub Real-time Push Service in the Cloud. @@ -16,93 +16,63 @@ ## This is a cloud-based service for broadcasting Real-time messages ## to thousands of web and mobile clients simultaneously. -## ---------------------------------------------------- -## Third Party Libraries Dependency -## ---------------------------------------------------- -## You must download and install, -## -## 1. pyopenssl -## Download from https://launchpad.net/pyopenssl -## -## 2. pycrypto -## Download from https://github.com/dlitz/pycrypto OR -## from http://code.google.com/p/uploadprj/downloads/detail?name=pycrypto-2.3.win32-py2.7.zip&can=2&q + +from Pubnub import PubnubTornado as Pubnub ## --------------- ## Python Push API ## --------------- -pubnub = Pubnub( - "demo", ## PUBLISH_KEY - "demo", ## SUBSCRIBE_KEY - "demo", ## SECRET_KEY - "", ## CIPHER_KEY (Cipher key is Optional) - False ## SSL_ON? -) +pubnub = Pubnub(publish_key="demo", subscribe_key="demo", ssl_on=False) ## ----------------------------------------------------------------------- ## IO Event Loop ## ----------------------------------------------------------------------- ## VERY IMPORTANT TO ADD THIS LINE AT THE VERY BOTTOM! ## -## tornado.ioloop.IOLoop.instance().start() ## IMPORTANT! +## pubnub.start() ## IMPORTANT! ## ## ----------------------------------------------------------------------- ## Subscribe Example ## ----------------------------------------------------------------------- -def connected() : - ## ----------------------------------------------------------------------- - ## Publish Example - ## ----------------------------------------------------------------------- - def publish_complete(info): - print(info) - - pubnub.publish({ - 'channel' : "my-tornado-channel", - 'message' : { - 'some_text' : 'Hello World!' - }, - 'callback' : publish_complete - }) - -def message_received(message): +channel = 'hello_world' + +def callback(message, channel): print(message) -pubnub.subscribe({ - 'channel' : "my-tornado-channel", - 'connect' : connected, - 'callback' : message_received -}) -## ----------------------------------------------------------------------- -## Time Example -## ----------------------------------------------------------------------- -def time_complete(timestamp): - print(timestamp) +def error(message): + print("ERROR : " + str(message)) + + +def connect(message): + print("CONNECTED") + + +def reconnect(message): + print("RECONNECTED") + + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, + connect=connect, reconnect=reconnect, disconnect=disconnect) -pubnub.time({ 'callback' : time_complete }) ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- -def history_complete(messages): - print(messages) +def callback(message): + print(message) + +pubnub.history(channel, count=2, callback=callback, error=callback) -pubnub.history( { - 'channel' : "my-tornado-channel", - 'limit' : 10, - 'callback' : history_complete -}) -## ----------------------------------------------------------------------- -## UUID Example -## ----------------------------------------------------------------------- -uuid = pubnub.uuid() -print "UUID" -print uuid ## ----------------------------------------------------------------------- ## IO Event Loop ## ----------------------------------------------------------------------- -tornado.ioloop.IOLoop.instance().start() +pubnub.start() |
