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


Python Packet.byte_to_Packet方法代码示例

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


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

示例1: write_packets

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def write_packets(expected, outfile, r_in, r_out):
    r_in.setblocking(True)
    rcvd_bytes, address = r_in.recvfrom(1024)
    rcvd = Packet.byte_to_Packet(rcvd_bytes)
    if (rcvd.magicno == 0x497E and rcvd.packet_type == 0):  # only run if it works, otherwise packet dropped
        acknowledgement_packet = Packet.Packet(0x497E, 1, rcvd.seqno, 0, '')         
        awk_buffer = acknowledgement_packet.convert_to_bytes()          
        r_out.sendto(awk_buffer, (ip, Port.cr_in_port))      
        print("twas sent right?")
        print("seqno: " + str(rcvd.seqno))
        if rcvd.seqno == expected:
            # rcvd is the received data packet # empty data field
            expected = 1 - expected
            print("length: " + str(rcvd.data_len))
            if rcvd.data_len > 0:
                print("this is data: " + rcvd.data)
                outfile.write(rcvd.data)
            elif rcvd.data_len == 0:
                outfile.close()
                r_in.close()  # unnecessary?
                r_out.close()
                exit()
    else:       
        # we should test some with weird or missing magicnos, if we havent already
        print("Error: invalid magicno. Must be 0x497E")
    return expected;
开发者ID:yabbyo,项目名称:264life,代码行数:28,代码来源:Reciever1.py

示例2: carry_on

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def carry_on(exit_flag, inputfile, next1, num_of_packets):
    rcvd_bytes, address = Socket.s_in.recvfrom(1024)
    rcvd = Packet.byte_to_Packet(rcvd_bytes)  # converts bytes to the recieved ack_packet
    if rcvd.magicno == 0x497E and rcvd.packet_type == 1 and rcvd.data_len == 0:
        if rcvd.seqno == next1:
            next1 = 1 - next1
            if exit_flag == True:
                inputfile.close()
                print("It took " + str(num_of_packets) + " packets to send the file")
                exit()
                # else go back to beginning of outer loop, idk if we need an else statement or it will do it itself ya feel me
    return next1
开发者ID:yabbyo,项目名称:264life,代码行数:14,代码来源:Sender.py

示例3: carry_on

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def carry_on(exit_flag, inputfile, next1, num_of_packets, outOfLoop):
    print("what")
    rcvd_bytes, address = Socket.s_in.recvfrom(1024)
    rcvd = Packet.byte_to_Packet(rcvd_bytes)  # converts bytes to the recieved ack_packet
    if rcvd.magicno == 0x497E and rcvd.packet_type == 1 and rcvd.data_len == 0:
        if rcvd.seqno == next1:
            next1 = 1 - next1
            if exit_flag == True:
                inputfile.close()
                print("It took " + str(num_of_packets) + " packets to send the file")
                exit()
            else:
                outOfLoop = True
                num_of_packets += 1  # add to number of packets sent (included repeated packets)
    return (outOfLoop, num_of_packets, next1)
开发者ID:yabbyo,项目名称:264life,代码行数:17,代码来源:Sender1.py

示例4: write_packets

# 需要导入模块: import Packet [as 别名]
# 或者: from Packet import byte_to_Packet [as 别名]
def write_packets(expected, outfile, r_in, r_out):
    r_in.setblocking(True)
    rcvd_bytes, address = r_in.recvfrom(1024)
    rcvd = Packet.byte_to_Packet(rcvd_bytes)
    if rcvd.magicno == 0x497E:  # only run if it works, otherwise packet dropped
        acknowledgement_packet = Packet.Packet(0x497E, 1, rcvd.seqno, 0,
                                               '')  # rcvd is the received data packet # empty data field
        awk_buffer = acknowledgement_packet.convert_to_bytes()  # when do we use this?
        expected = 1 - expected
        if rcvd.data_len > 0:
            outfile.write(rcvd.data)
        elif rcvd.data_len == 0:
            outfile.close()
            r_in.close()  # unnecessary?
            r_out.close()
            exit()
    else:
        # we should test some with weird or missing magicnos, if we havent already
        print("Error: invalid magicno. Must be 0x497E")
开发者ID:yabbyo,项目名称:264life,代码行数:21,代码来源:Receiver.py


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