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


Python packet.Packet类代码示例

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


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

示例1: test_average_bitrate_single_packet

 def test_average_bitrate_single_packet(self):
     for i in range(10):
         packet_size_bytes = random.uniform(1.0, 8000.0)
         delay_ms = random.uniform(10.0, 300.0)
         packet = Packet(1, 0.0, packet_size_bytes)
         packet.arrival_time_ms = delay_ms
         self.assertEqual(average_bitrate_kbps([packet]), 8.0 * packet_size_bytes / delay_ms)
开发者ID:cesar-ilharco,项目名称:rmcat_evaluation,代码行数:7,代码来源:bwe_utils_unittest.py

示例2: run

 def run(self):
     while 1:
         msg = self.connection.recv(1024)
         data = bytearray(msg)
         pck = Packet()
         pck.data = data
         self.onpacketdata(pck.getPacketID(), data)
开发者ID:aroncds,项目名称:ragnarok2-pythonserver,代码行数:7,代码来源:loginsession.py

示例3: on_tunnel_received

 def on_tunnel_received(_, __, data):
     packet = Packet(data)
     addr_list, id_, _ = try_parse_dns_result(packet)
     if addr_list is not None:
         update_blocked_address(addr_list)
         try_restore_dns(packet, id_)
     tundev.send(packet.get_packet())
开发者ID:binasc,项目名称:utils,代码行数:7,代码来源:tuntun.py

示例4: run

 def run(self):
     while True:
         data, addr = self.server.recv()
         pkg = Packet.unpack(data)
         # print "got packet: %s, %s, %s" % (pkg.tick, pkg.players, pkg.input)
         with self.lock:
             net_tick = self.parent.net_tick
             if addr not in self.clients:
                 if pkg.tick == 0 and len(pkg.players) == 0 and len(pkg.input) == 0:
                     self.clients[addr] = Client(addr, self.next_id, Player(50 + self.next_id * 30, 50))
                     self.next_id += 1
                     pkg_response = Packet(net_tick)
                     pkg_response.add_player(self.clients[addr].id, self.clients[addr].player)
                     self.server.send(pkg_response, addr)
                     print "authenticating new client: %s -> %s" % (addr, self.clients[addr].id)
                 else:
                     print "invalid authentication attempt: %s, %s, %s" % (pkg.tick, pkg.players, pkg.input)
             else:
                 client = self.clients[addr]
                 client.ack()
                 if pkg.tick >= net_tick:
                     if len(pkg.input) > 0:
                         client.events[pkg.tick] = pkg.input
                     # if net_tick not in self.pkg_queue:
                     # self.pkg_queue[net_tick] = []
                     # self.pkg_queue[net_tick].insert(0, pkg)
                 else:
                     print "discard packet (too old: %d < %d)" % (pkg.tick, net_tick)
开发者ID:oncer,项目名称:netproto,代码行数:28,代码来源:np_server.py

示例5: transfer_file

	def transfer_file(self, share_ID, file_name, return_address, start_offset=0, end_offset=999999999999, block_skip=1):
		"""Sends a piece of a file to a peer in pieces.
		Initiated by JSONRPC: get_file()
		start_offset: start sending file from this offset
		end_offset: if this bytes is reached, send no more.
		block_skip: send a block, then skip this many blocks, then send the next etc.
		"""
		#continue to send all file blocks
		full_file_path = os.path.join(self.storage_directory, share_ID, file_name)
		f = open(full_file_path, 'rb')
		f.seek(start_offset)
		block_size = 5
		file_offset = start_offset
		
		logging.debug('file_name: %s start_offset: %d, end_offset: %d' %(file_name, start_offset, end_offset))
		
		while (file_offset < end_offset):  #@TODO: stop sending if given signal from return_address
			logging.debug('file_offset: %d' %(file_offset))
			block_bytes = f.read(64*block_size)
			if block_bytes == "":
				logging.debug('no bytes read from file')
				break
			p_out_block = Packet()
			p_out_block.json_RPC_object = dict(jsonrpc="2.0", method="save_file_block", params=[1.0, None, [self.my_machine_ID, share_ID, file_name, file_offset]], )  #id=rpc_id
			p_out_block.binary_blob = block_bytes
			p_out_block.to_address = return_address
			
			self.send_block_choke(p_out_block, return_address, 3)
			
			time.sleep(0.002)
			file_offset+=block_size
		
		logging.debug('finished file transfer')
		f.close()
开发者ID:stevenleigh,项目名称:sib,代码行数:34,代码来源:jsonserver.py

示例6: _send_command

    def _send_command(self, command, data):
        p = Packet(seq=self.tx_seq, cmd=command, data=data, seq_sync=False)
        msg = p.toMessage(key = self.key)

        self.logger.debug('%s Msg to door: %s'%(self.name, list(p.toMessage())))
        self.interface.writeMessage(self.priority, self.address, msg, self.tx_msg_queue)
        self.tx_seq += 1
开发者ID:muccc,项目名称:luftschleuse2,代码行数:7,代码来源:door.py

示例7: run

    def run(self):
        """
        Run the ETL Chain.
        :return:
        """
        log.info('Running Chain: %s' % self.chain_str)

        # One time init for entire Chain
        self.first_comp.do_init()

        # Do ETL as long as input available in Packet
        packet = Packet()
        rounds = 0
        try:
            while not packet.is_end_of_stream():
                # try:
                # Invoke the first component to start the chain
                packet.init()
                packet = self.first_comp.process(packet)
                rounds += 1
                #            except (Exception), e:
                #                log.error("Fatal Error in ETL: %s"% str(e))
                #                break
        finally:
            # Always one time exit for entire Chain
            self.first_comp.do_exit()

        log.info('DONE - %d rounds - chain=%s ' % (rounds, self.chain_str))
开发者ID:fsteggink,项目名称:stetl,代码行数:28,代码来源:chain.py

示例8: _send_command

    def _send_command(self, command, data):
        p = Packet(seq=self.txseq, cmd=command, data=data)
        self.logger.debug("Msg to mastercontroller: %s" % list(p.toMessage()))

        msg = self.aes.encrypt([ord(x) for x in p.toMessage()], self.key, AES.keySize["SIZE_128"])
        msg = "".join([chr(x) for x in msg])
        self.interface.writeMessage(self.address, msg)
开发者ID:nictally,项目名称:luftschleuse2,代码行数:7,代码来源:mastercontroller.py

示例9: test_drop_old_packet

 def test_drop_old_packet(self):
     w1 = Node(name="w1")
     p = Packet(content="X", receiver="w2", sender="w3")
     p._hopcounter = p.MAX_HOP
     w1.drop_packet = FunctionCalledChecker(w1.drop_packet)
     w1.accept(p)
     self.assertTrue(w1.drop_packet.was_called)
开发者ID:grapo,项目名称:ETO,代码行数:7,代码来源:tests.py

示例10: test_valid_packet_counter

    def test_valid_packet_counter(self):
        p = Packet(content="content", receiver="receiver")
        self.assertFalse(p.is_looped())
        for i in range(Packet.MAX_HOP - 1):
            p.hop()

        self.assertFalse(p.is_looped())
开发者ID:grapo,项目名称:ETO,代码行数:7,代码来源:tests.py

示例11: get

 def get(self):
     import sys
     pkt = Packet()
     args = map(lambda v: String(v), sys.argv)
     pkt.item = Array(args)
     pkt.item.append(String("aaa"))
     pkt.item.append(Url("http://www.yahoo.co.jp/"))
     return chain([pkt,])
开发者ID:calmsea,项目名称:tugi,代码行数:8,代码来源:member.py

示例12: __init__

 def __init__(self,source_address=1,source_port=0,
              destination_address=1,destination_port=0,
              ident=0,protocol="TCP",body="",length=0,
              syn=False,ack=False,fin=False,sequence=0,ack_number=0):
     Packet.__init__(self,source_address,source_port,destination_address,
                     destination_port,ident,protocol,body,length)
     self.sequence = sequence
     self.ack_number = ack_number
开发者ID:Steve525,项目名称:bene,代码行数:8,代码来源:tcppacket.py

示例13: packet_read

    def packet_read(self, conn, raw_packet):
        """
        Read in a packet and dispatch -- asyncore callback.
        """
        packet = Packet.decode(raw_packet)
        print "packet in with protocol"

        if Packet.is_named(packet.protocol):
            # protocol is named, resolve id first
            name = packet.protocol
            id = self.server_map.resolve_id(name)

            if id:
                named = MappedName()
                named.name = name
                named.id = id
                msg = Message(0, named)
                self.q_out.fifo_put((conn, msg))
            else:
                print "unmapped name: " + str(name)
                rejected = MessageRejected()
                rejected.id = 0
                rejected.reason = rejected.UNMAPPED_NAME
                rejected.message = "Unmapped name: '%s'" % name
                msg = Message(0, rejected)
                self.q_out.fifo_put((conn, msg))
                # stop processing
                return

        else:
            # just take id
            id = packet.protocol

        # this seems slightly silly in the case where the message was
        # a named message (it shouldn't hurt though)
        name = self.server_map.resolve_name(id)

        if not name:
            # if the reverse name lookup fails
            print "unmapped id: " + str(id)
            rejected = MessageRejected()
            rejected.id = 0
            rejected.reason = rejected.UNMAPPED_ID
            rejected.message = "Unmapped ID: %d" % id
            msg = Message(0, rejected)
            self.q_out.fifo_put((conn, msg))
            # stop processing
            return

        protobuf_class = self.server_map.resolve_protobuffer(name)
        assert protobuf_class

        protobuf = protobuf_class()
        protobuf.ParseFromString(packet.payload)
        message = Message(packet.track_id, protobuf, name=name)
        print "have protobuf: {" + str(protobuf) + "}"

        self.q_in.fifo_put((conn, message))
开发者ID:norbert-jiang,项目名称:tinyos-2.x-contrib,代码行数:58,代码来源:server.py

示例14: _send_command

    def _send_command(self, command, data):
        p = Packet(seq=self.txseq, cmd=command, data=data)
        msg = self.aes.encrypt([ord(x) for x in p.toMessage()], self.key,
                    AES.keySize["SIZE_128"])
        msg = ''.join([chr(x) for x in msg])

        self.logger.debug('Msg to door %s: %s'%(self.name, list(p.toMessage())))
        self.interface.writeMessage(self.address, msg)
        '''
开发者ID:nictally,项目名称:luftschleuse2,代码行数:9,代码来源:door.py

示例15: encode

 def encode(self, protocol):
     """
     Encodes the message as a packet (serializing it first if
     needed) using the given protocol.
     """
     if not self.serialized:
         self.serialized = self.pbuffer.SerializeToString()
     packet = Packet(self.track_id, protocol, self.serialized)
     return packet.encode()
开发者ID:KPyda,项目名称:tinyos-2.x-contrib,代码行数:9,代码来源:message.py


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