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


Python Packet.overridePacketLength方法代码示例

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


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

示例1: main

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import overridePacketLength [as 别名]
def main(tout, filename):
    global timeout
    global hostname
    global portnum
    global file_contents
    global total_packets
    global payload_max
    global len_of_chunks
    
    timeout = int(tout)
    channelInfo = open("channelInfo", 'r')
    deets = channelInfo.read().split(' ')
    hostname = deets[0]
    portnum = int(deets[1])
    clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    print payload_max
    print filename
    try:
        with open(filename, 'rb') as f:
            sequenceNum = 0
            while True:
                packet = struct.pack("L4", PacketType.DataPacket)
                packet += struct.pack("L4", sequenceNum)

                f.seek(sequenceNum * payload_max)
                chunk = f.read(payload_max)
                if chunk:
                    length_of_chunk = sys.getsizeof(chunk)
                    packet += struct.pack("L4", length_of_chunk+12)
                    print length_of_chunk
                    packet += struct.pack("s"+str(length_of_chunk), chunk)
                    file_contents.append(packet)
                    chunk_packet = Packet()
                    chunk_packet.changeSequenceNum(sequenceNum)
                    chunk_packet.overridePacketLength(length_of_chunk)
                    len_of_chunks.append(chunk_packet)
                    sequenceNum = sequenceNum + 1
                else:
                    break
    except:
        print "Failed to open file to transmit"
        sys.exit(0)

    total_packets = len(file_contents)
    sendFiles(clientSocket)
开发者ID:ameesha,项目名称:GBN_ARQ,代码行数:48,代码来源:srSender.py


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