Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
65 lines (48 loc) · 1.3 KB

File metadata and controls

executable file
·
65 lines (48 loc) · 1.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
sys.path.append('../')
import threading
import time
import random
import string
from Pubnub import Pubnub
## Initiate Class
pubnub = Pubnub( 'demo', 'demo', None, False )
print("My UUID is: "+pubnub.uuid)
channel = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(20))
## Subscribe Example
def receive(message) :
print(message)
return False
def pres_event(message):
print(message)
return False
def subscribe():
print("Listening for messages on '%s' channel..." % channel)
pubnub.subscribe({
'channel' : channel,
'callback' : receive
})
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()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.