当前位置: 首页>>代码示例>>Python>>正文


Python Pubnub.start方法代码示例

本文整理汇总了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()
开发者ID:agilemobiledev,项目名称:examples-2,代码行数:18,代码来源:subscribe_devices.py

示例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()
开发者ID:agilemobiledev,项目名称:examples-2,代码行数:32,代码来源:pub_sub.py


注:本文中的pubnub.Pubnub.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。