Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created January 22, 2019 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajb413/ec1364a02560a35bc9027e21dc42e706 to your computer and use it in GitHub Desktop.
Save ajb413/ec1364a02560a35bc9027e21dc42e706 to your computer and use it in GitHub Desktop.
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNStatusCategory
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
import time
import os
pnconfig = PNConfiguration()
pnconfig.publish_key = 'enter your pubnub publish key here'
pnconfig.subscribe_key = 'enter your pubnub subscribe key here'
pnconfig.ssl = True
pubnub = PubNub(pnconfig)
def my_publish_callback(envelope, status):
# Check whether request successfully completed or not
if not status.is_error():
pass
class MySubscribeCallback(SubscribeCallback):
def presence(self, pubnub, presence):
pass
def status(self, pubnub, status):
pass
def message(self, pubnub, message):
print "from device 2: " + message.message
pubnub.add_listener(MySubscribeCallback())
pubnub.subscribe().channels("chan-1").execute()
## publish a message
while True:
msg = raw_input("Input a message to publish: ")
if msg == 'exit': os._exit(1)
pubnub.publish().channel("chan-1").message(str(msg)).pn_async(my_publish_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment