예제 #1
0
from Pubnub import Pubnub

publish_key   = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key    = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key    = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on        = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on )
crazy  = 'hello_world'

## -----------------------------------------------------------------------
## History Example
## -----------------------------------------------------------------------
def here_now_complete(messages):
    print(messages)
    pubnub.stop()

pubnub.here_now( {
    'channel'  : crazy,
    'callback' : here_now_complete
})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
pubnub.start()
예제 #2
0
sys.path.append('../../common')
from Pubnub import Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on)
crazy = 'hello_world'


## -----------------------------------------------------------------------
## History Example
## -----------------------------------------------------------------------
def here_now_complete(messages):
    print(messages)
    pubnub.stop()


pubnub.here_now({'channel': crazy, 'callback': here_now_complete})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
pubnub.start()
예제 #3
0

def presence():
    print("Listening for presence events on '%s' channel..." % channel)
    pubnub.presence({'channel': channel, 'callback': pres_event})


def publish():
    print("Publishing a test message on '%s' channel..." % channel)
    pubnub.publish({'channel': channel, 'message': {'text': 'foo bar'}})


pres_thread = threading.Thread(target=presence)
pres_thread.daemon = True
pres_thread.start()

sub_thread = threading.Thread(target=subscribe)
sub_thread.daemon = True
sub_thread.start()

time.sleep(3)

publish()

print("waiting for subscribes and presence")
pres_thread.join()

print pubnub.here_now({'channel': channel})

sub_thread.join()
예제 #4
0
## http://www.pubnub.com/


import sys
from Pubnub import Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
channel = 'hello_world'


# Synchronous usage
print pubnub.here_now(channel)

# Asynchronous usage


def callback(message):
    print(message)

pubnub.here_now(channel, callback=callback, error=callback)
예제 #5
0
import sys
from Pubnub import Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key,
                subscribe_key=subscribe_key,
                secret_key=secret_key,
                cipher_key=cipher_key,
                ssl_on=ssl_on)
channel = 'hello_world'

# Synchronous usage
print pubnub.here_now(channel)

# Asynchronous usage


def callback(message):
    print(message)


pubnub.here_now(channel, callback=callback, error=callback)
예제 #6
0
## PubNub 3.1 Real-time Push Cloud API
## -----------------------------------

import sys
sys.path.append('../')
from twisted.internet import reactor
from Pubnub import Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key,
                subscribe_key=subscribe_key,
                secret_key=secret_key,
                cipher_key=cipher_key,
                ssl_on=ssl_on)
crazy = 'hello_world'


def print_cb(message):
    print message


pubnub.here_now({'channel': crazy, 'callback': print_cb})
예제 #7
0
## -----------------------------------
## PubNub 3.1 Real-time Push Cloud API
## -----------------------------------

import sys
sys.path.append('../')
from twisted.internet import reactor
from Pubnub import Pubnub

publish_key   = len(sys.argv) > 1 and sys.argv[1] or 'demo'
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo'
secret_key    = len(sys.argv) > 3 and sys.argv[3] or 'demo'
cipher_key    = len(sys.argv) > 4 and sys.argv[4] or ''
ssl_on        = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key,
    secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)
crazy  = 'hello_world'

def print_cb(message):
	print message

pubnub.here_now( {
    'channel'  : crazy,
    'callback' : print_cb
})

예제 #8
0
        'callback' : pres_event 
    })

def publish():
    print("Publishing a test message on '%s' channel..." % channel)
    pubnub.publish({
        'channel'  : channel,
        'message'  : { 'text':'foo bar' }
    })

pres_thread = threading.Thread(target=presence)
pres_thread.daemon=True
pres_thread.start()

sub_thread = threading.Thread(target=subscribe)
sub_thread.daemon=True
sub_thread.start()

time.sleep(3)

publish()


print("waiting for subscribes and presence")
pres_thread.join()

print pubnub.here_now({'channel':channel})

sub_thread.join()

예제 #9
0
def presence():
    print ("Listening for presence events on '%s' channel..." % channel)
    pubnub.presence({"channel": channel, "callback": pres_event})


def publish():
    print ("Publishing a test message on '%s' channel..." % channel)
    pubnub.publish({"channel": channel, "message": {"text": "foo bar"}})


pres_thread = threading.Thread(target=presence)
pres_thread.daemon = True
pres_thread.start()

sub_thread = threading.Thread(target=subscribe)
sub_thread.daemon = True
sub_thread.start()

time.sleep(3)

publish()


print ("waiting for subscribes and presence")
pres_thread.join()

print pubnub.here_now({"channel": channel})

sub_thread.join()