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


Python Packet.addData方法代码示例

本文整理汇总了Python中packet.Packet.addData方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.addData方法的具体用法?Python Packet.addData怎么用?Python Packet.addData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在packet.Packet的用法示例。


在下文中一共展示了Packet.addData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Packet

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import addData [as 别名]
#
packet = Packet(315)
#Now we can add data to the packet. Data in a packet is represented by the PacketData class,
#which passes 2 arguments. The first is the DID(Data ID), and the second is the actual data.
#We'll add one of each supported data type.
'''
Data Type Protocol:
1. String
2. Integer
3. Float
4. Boolean
5. (TODO) File
6. Other (Program uses JSON to convert value to string and back)
'''
#We'll add a string with DID 1
packet.addData(PacketData(1,"Testing 123"))
#We'll add an integer with DID 2
packet.addData(PacketData(2,123))
#We'll add a float with DID 3
packet.addData(PacketData(3,1.23))
#We'll add a boolean with DID 4
packet.addData(PacketData(4,True))
#We'll add a list(other) of different types of data with DID 5
packet.addData(PacketData(5,['321 Testing',123,1.23,True]))

#Two methods that allow us to discern data printed from server vs client
#Normally the server program would be seperate from that of the client though

def clientMsg(msg):
    print "[CLIENT] " + msg
    
开发者ID:opensourcehiker,项目名称:SPP,代码行数:32,代码来源:example.py


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