Exemplo n.º 1
0
## Copyright (c) 2010 Stephen Blum
## http://www.pubnub.com/


import sys
from Pubnub import PubnubTornado as Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or "pam"
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or "pam"
secret_key = len(sys.argv) > 3 and sys.argv[3] or "pam"
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"
authkey = "abcd"


def callback(message):
    print(message)


pubnub.grant(channel, authkey, True, True, callback=callback, error=callback)

pubnub.start()
Exemplo n.º 2
0

def error(message):
    print("ERROR : " + str(message))


def connect_abc(message):
    print("CONNECTED " + str(message))


def connect_d(message):
    print("CONNECTED " + str(message))
    pubnub.unsubscribe(channel='d')


def reconnect(message):
    print("RECONNECTED " + str(message))


def disconnect(message):
    print("DISCONNECTED " + str(message))


print pubnub.channel_group_add_channel(channel_group='abc', channel="bn")

pubnub.presence_group(channel_group='abc', callback=callback_abc, error=error)

pubnub.presence(channel='d', callback=callback_d, error=error)

pubnub.start()
Exemplo n.º 3
0
x = 5
def run_test(t):
	global x
	x += 5
	i = (x / 5) - 1
	def _print():
		print('Running test ' + str(i))
	pubnub.timeout(x, _print)
	pubnub.timeout(x + 1,t)

def stop():
	pubnub.stop()

run_test(test_1)
run_test(test_2)
run_test(test_3)
run_test(test_4)
run_test(test_5)
run_test(test_6)
run_test(test_7)
run_test(test_8)
run_test(test_9)
run_test(test_10)
run_test(test_11)
run_test(stop)


pubnub_pam.start()