本文整理汇总了Python中pubnub.Pubnub.start方法的典型用法代码示例。如果您正苦于以下问题:Python Pubnub.start方法的具体用法?Python Pubnub.start怎么用?Python Pubnub.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pubnub.Pubnub
的用法示例。
在下文中一共展示了Pubnub.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import start [as 别名]
def main(channel="devices", host="localhost", port=8086):
#
#initialize the PubNub handle
#
pub_key = os.environ['PUB_KEY']
sub_key = os.environ['SUB_KEY']
pubnub = Pubnub(publish_key=pub_key, subscribe_key=sub_key)
signal.signal(signal.SIGINT, signal_handler)
# subscribe to a channel and invoke the appropriate callback when a message arrives on that
# channel
#
print("Subscribing from PubNub Channel '%s'" % (channel))
pubnub.subscribe(channels=channel, callback=receive, error=on_error)
pubnub.start()
示例2: on_reconnect
# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import start [as 别名]
for msg in messages:
pubnub.publish(channel="msg_channel", message=msg)
#
# callback when connected to the PubHub network
#
def on_reconnect(message):
print ("RECONNECTED")
#
# callback whtn disconnected from the PubHub network
def on_disconnect(message):
print ("DISCONNECTED")
if __name__ == "__main__":
#
# get keys from the environment variable
#
pub_key=os.environ['PUB_KEY']
sub_key=os.environ['SUB_KEY']
#
# initate the Pubnub instance
# subsistute your publish_key and subscribe_key here, if you want more security. But demo should wor
pubnub = Pubnub(publish_key=pub_key, subscribe_key=sub_key)
#
# subscribe to a channel and invoke the appropriate callback when a message arrives on that
# channel
#
pubnub.subscribe(channels="json_channel", callback=sub_callback, error=on_error,
connect=on_connect_json, reconnect=on_reconnect, disconnect=on_disconnect)
pubnub.start()