本文整理汇总了Python中Packet.Packet类的典型用法代码示例。如果您正苦于以下问题:Python Packet类的具体用法?Python Packet怎么用?Python Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
def send(self, flag, message):
#print ("\nTYPE = " + self.type)
self.send_buffer = message
if self.remote == None:
raise 'must call "bind()" first'
#client initializes connection
elif flag == None and self.type == "CLIENT" and self.STATE == "ESTABLISHED":
buffer = []
while len(message) > 0:
buffer.append(message[:self.window_size])
if len(message) < self.window_size:
message = ''
else:
message = message[self.window_size:len(message)]
for s in buffer:
pack = Packet(s, self.remote)
pack.flag = None
pack.seq_number = self.packet_number
top_data = pack.seq_number + pack.length
print ("-> data " + str(pack.seq_number) + " - " + str(top_data))
self.packet_number = top_data
self.cache[pack.seq_number + pack.length] = pack, self.current_time()
self.sched.add(self.current_time(), pack, self.send_data)
示例2: _send_ack
def _send_ack(self):
packet = Packet()
packet.set("specification", "setting_ack")
packet.set("next_index", self._next_index)
packet.set("sensor_id", self._rf_sensor.id)
self._rf_sensor.enqueue(packet, to=0)
示例3: __init__
def __init__(self, byteCodeId=None, data=None):
if data != None:
Packet.__init__(self, b"\x5A", b"\xA5", byteCodeId)
self.__data = data
else:
length = len(byteCodeId)
if length >= 8:
if byteCodeId[0]== b"\x5A" and byteCodeId[1]== b"\xA5":
Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4])
self.__data = byteCodeId[4:length-2]
#print("com1:", self.__commandCode0)
#print("com2:", self.__commandCode1)
#print("Id:", self.__deviceId)
#print("rawData:", self.__data)
#checkRec = bytearray(byteCode)[length-2] + bytearray(byteCode)[length-1]
#print("checkRec:", checkRec)
#print("checkRec:", receivedByteArray[length-2:length])
#checkCalc = bytearray(super.getCheckSum())[0]+ bytearray(super.getCheckSum())[1]
#print("checkCalc:", checkCalc)
#print("checkCalc:", self.getCheckSum())
#if self.getCheckSum() != receivedByteArray[length-1:length]:
#if checkRec != checkCalc:
if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]:
raise SensorException(CHECKSUM_ERROR, DATA_PACK_ERROR)
else:
raise SensorException(PACKET_HEADER_ERROR,DATA_PACK_ERROR)
else:
raise SensorException(LENGTH_ERROR, DATA_PACK_ERROR)
示例4: createAndSendPacket
def createAndSendPacket(destinationId,ttl,msgType,timestamp,payload):
p = Packet()
p.initialise(0,destinationId,ttl,msgType,timestamp,payload)
print "Creating and Sending: "
print p
global sendingSocket
sendingSocket.sendData(p.getBytes())
示例5: __init__
def __init__(self, byteCodeId=None, comResp=None, parameter=None):
if comResp != None:
#super().__init__(b"\x55", b"\xAA", byteCodeId)
Packet.__init__(self, b"\x55", b"\xAA", byteCodeId)
self.__parameter = parameter
self.__comResp = comResp
else:
length = len(byteCodeId)
if length == 12:
if byteCodeId[0]== b"\x55" and byteCodeId[1]== b"\xAA":
Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4])
self.__parameter = byteCodeId[4:8]
self.__comResp = byteCodeId[8:10]
#print("com1:", self.__commandCode0)
#print("com2:", self.__commandCode1)
#print("deviceId:", self.__deviceId)
#print("parameter:", self.__parameter)
#print("comResp:", self.__comResp)
#print("check:", receivedByteArray[10:12])
#print("checkCalc:",self.getCheckSum())
if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]:
raise SensorException(CHECKSUM_ERROR, COMMAND_PACK_ERROR)
else:
raise SensorException(PACKET_HEADER_ERROR, COMMAND_PACK_ERROR)
else:
raise SensorException(LENGTH_ERROR, COMMAND_PACK_ERROR)
示例6: create_tournament_from_directory
def create_tournament_from_directory(self, dir, reuse_html=False):
conf_file = os.path.join(dir, 'config.json')
if not os.path.exists(conf_file):
conf_file = conf_gen(dir, '*.docx')
conf_dict = json.load(open(conf_file, 'r'))
self.tour_name = conf_dict['tournament']
self.year = conf_dict['year']
packets = conf_dict['packets']
for file_entry in packets:
packet_file = os.path.join(dir, file_entry['filename'])
packet_author = file_entry['author']
packet = Packet(packet_author, tournament=self.tour_name)
try:
packet.load_packet_from_file(packet_file, reuse_html=reuse_html)
except PacketParserError as ex:
self.errors.append(ex)
self.add_packet(packet)
示例7: callback
def callback(self, pck):
#ipdb.set_trace()
cont = pck.pop_float_list()
print "Received new packet: " + repr(cont)
out = Packet()
out.append_float_list(cont)
self.conn.sendPacket(out)
示例8: callback
def callback(self, pck):
print "Received new packet: " + repr(pck.read_float_list())
raw_input()
out = Packet()
out.put_float_list(pck.read_float_list())
print "Sending packet back "
self.conn.sendPacket(out)
print "Done."
示例9: send_init
def send_init():
# Send initialisation information from mesh
print "Connecting to mesh network..."
global mesh_listening_socket, mesh_sending_socket, n_players, base_location
mesh_listening_socket = SocketConnection('localhost')
# Perform initialisation actions with mesh: get location and assign addresses.
while True:
if mesh_listening_socket.connectAsReceiver():
mesh_sending_socket = SocketConnection('', 29877)
if mesh_sending_socket.connectAsSender():
# Start the connection to the mesh
print "Sending init packet to mesh"
mesh_sending_socket.sendData('*')
# Get the base station location packet
firstData = mesh_listening_socket.receiveData()
print "First Data: " + firstData.encode('hex_codec')
first_packet = Packet(firstData)
first_payload = first_packet.getPayload()
print first_payload
mesh_listening_socket.setTimeout(1.0)
n_players = 3
# Assign addresses to the expected number of nodes
s_time = time.time()
while (len(id_dict) <= 1):
if (time.time() > s_time + 10):
break;
print "Time remaining: " + str(int(s_time + 10 - time.time() + 0.5))
try:
data = mesh_listening_socket.receiveData()
packet = Packet(data)
if packet.isIdentification():
speck_id = packet.getPayload().getId()
print "Id request from %s" % speck_id
id_dict.append(speck_id)
# Respond to all requests: packet may have dropped
assign_address(speck_id)
print "Address assigned"
# Reset the start time so we wait from last receive
s_time = time.time()
print "Time Reset"
except:
print "No Data received. Retrying"
break
# If creating sockets doesn't work, wait and try again
else:
time.sleep(1)
else:
time.sleep(1)
assign_names()
示例10: create_and_send_packet
def create_and_send_packet(destinationId,ttl,msgType,timestamp,payload):
global mesh_sending_socket
p = Packet()
p.initialise(0,destinationId,ttl,msgType,timestamp,payload)
print "Creating and Sending: " + str(p)
try:
mesh_sending_socket.sendData(p.getBytes())
print "sent"
except:
print "A connection error happened. Are you simulating the mesh?"
示例11: generatePacket
def generatePacket( targetDistribution, packet ):
sample = DirectTargetSampling.sampleFromDistribution( targetDistribution )
if sample == None:
newLen = 1500
else:
bits = sample.split('-')
newLen = int(bits[1])
packet = Packet( packet.getDirection(), packet.getTime(), newLen )
return packet
示例12: connect
def connect(self):
address = "192.168.235.6"
self.conn.createClient(address, 5000)
while True:
pck = Packet()
dat = [random.random() for _ in range(10)]
pck.put_float_list(dat)
print "Sending: " + repr(dat)
self.conn.sendPacket(pck)
raw_input()
示例13: user_state
def user_state(self, leg, shoulder, elbow, foot):
user_packet = Packet()
if leg == 1:
self.leg_1.set_angles(shoulder, elbow, foot)
elif leg == 2:
self.leg_2.set_angles(shoulder, elbow, foot)
elif leg == 3:
self.leg_3.set_angles(shoulder, elbow, foot)
elif leg == 4:
self.leg_4.set_angles(shoulder, elbow, foot)
elif leg == 5:
self.leg_5.set_angles(shoulder, elbow, foot)
elif leg == 6:
self.leg_6.set_angles(shoulder, elbow, foot)
user_packet.set_leg(1, self.leg_1)
user_packet.set_leg(2, self.leg_2)
user_packet.set_leg(3, self.leg_3)
user_packet.set_leg(4, self.leg_4)
user_packet.set_leg(5, self.leg_5)
user_packet.set_leg(6, self.leg_6)
user_packet.make_packet()
packet_list = [user_packet]
return packet_list
示例14: data_received
def data_received(self, data):
"""
incoming data are ready
"""
# compute all packets
while (len(data) > 0):
packet = Packet(data)
size = packet.getVarint()
offset = packet.getVarintSize()
packet = Packet(data[offset:offset+size])
# compute the packet
self.protocol.Receive(packet)
# remove the packet
data = data[offset+size:]
示例15: connect
def connect(self, connect_handler):
#create SYN packet
# print ("I AM A CLIENT")
self.type = "CLIENT"
packet = Packet(None, (self.host.address, self.host.port))
packet.flag = "SYN"
self.STATE = __SYN_SENT__
print ("LISTEN <- SYN")
#put SYN packet on the link
packet.set_key("SYN")
self.cache[packet.key] = packet
self.sched.add(self.current_time(), packet, self.send_data)
#print "sent: " + str(packet.fla)
self.connect_handler = connect_handler