本文整理汇总了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