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


Python Packet.set_key方法代码示例

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


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

示例1: connect

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import set_key [as 别名]
    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
开发者ID:itcropper,项目名称:TCP,代码行数:20,代码来源:Socket.py

示例2: store

# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import set_key [as 别名]
    def store(self, time, packet):

        #print ("TYPE:" + self.type, "FLAG:" + str(packet.flag), "STATE: " + self.STATE + "\n")
        #print ("\n")
        if packet.body:
            self.buffer = packet.body
            print (self.buffer)

        if self.type == "SERVER":

            #Client sent out ACK, now server is fully connected
            if packet.flag == "ACK" and self.STATE == __SYN_RCVD__:

                print ("ACK-RCVD")
                print (__SYN_RCVD__, "->", __ESTABLISHED__)
                self.STATE = __ESTABLISHED__
                a = self
                self.accept_handler(self.current_time(), a)

            elif packet.flag == "ACK" and self.STATE == __ESTABLISHED__:
                pack = Packet(None, self.remote)
                pack.flag = "ACK"

                self.STATE == __CLOSE_WAIT__
                self.cache[pack.key] = pack
                self.sched.add(self.current_time(), pack, self.send_data)

            elif packet.flag == "ACK" and self.STATE == __LAST_ACK__:
                self.STATE == __CLOSED__
                print (__LAST_ACK__, "->", __CLOSED__)
                return


            elif packet.flag == None and self.STATE == __ESTABLISHED__:
                #s = raw_input(str(packet.seq_number) + " : " + str(self.packet_number))
                if self.packet_number  == packet.seq_number:
                    #print (self.packet_number, packet.seq_number, packet.length)
                    #s = raw_input("self.packet_number  == packet.seq_number")
                    pack = Packet(None, self.remote)
                    pack.flag = "ACK"
                    #print (packet.seq_number)
                    pack.server_ack = packet.seq_number + packet.length
                    self.packet_number = pack.server_ack
                    self.cache[pack.key] = pack
                    #print ("Packet Number: " + str(self.packet_number))
                    print ("<- ack " + str(pack.server_ack))
                    self.sched.add(self.current_time(), self.buffer, self.recv_handler)
                    self.sched.add(self.current_time(), pack, self.send_data)
                else:
                    #print (self.packet_number, packet.seq_number, packet.length)
                    #s = input("self.packet_number !!!= packet.seq_number")
                    self.cache[packet.seq_number] = packet
                    pack = Packet(None, self.remote)
                    pack.flag = "ACK"
                    #print (packet.seq_number)
                    self.cache[pack.key] = pack
                    pack.server_ack = self.packet_number
                    self.packet_number = pack.server_ack
                    print ("<- ack " + str(pack.server_ack))
                    self.sched.add(self.current_time(), self.buffer, self.recv_handler)
                    self.sched.add(self.current_time(), pack, self.send_data)

            elif packet.flag == "FIN" and self.STATE == __ESTABLISHED__:
                pack1 = Packet(None, self.remote)
                pack1.flag = "ACK"
                self.STATE = __CLOSE_WAIT__
                print (__ESTABLISHED__, "->", __CLOSE_WAIT__)
                pack1.set_key("ACK")

                self.cache[pack1.key] = pack1

                self.sched.add(self.current_time(), pack1, self.send_data)
                pack2 = Packet(None, self.remote)
                pack2.flag = "FIN"
                self.STATE = __LAST_ACK__
                pack2.set_key("FIN")
                self.cache[pack2.key] = pack2
                print (__CLOSE_WAIT__, "->", __LAST_ACK__)
                self.sched.add(self.current_time(), pack2, self.send_data)

            elif packet.flag == "SYN" and self.STATE == __CLOSED__:
                
                self.STATE = __SYN_RCVD__

                pack = Packet(None, self.remote)
                pack.flag = "SYNACK"
                print ("SYN-RCVD -> SYN+ACK")

                pack.set_key('SYNACK')

                self.cache[pack.key] = pack

                
                self.sched.add(self.current_time(), pack, self.send_data)
                '''
                pass
                '''

        #Must be a client
        else:
#.........这里部分代码省略.........
开发者ID:itcropper,项目名称:TCP,代码行数:103,代码来源:Socket.py


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