本文整理汇总了Python中Packet.Packet.flag方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.flag方法的具体用法?Python Packet.flag怎么用?Python Packet.flag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet.Packet
的用法示例。
在下文中一共展示了Packet.flag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import flag [as 别名]
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: connect
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import flag [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
示例3: store
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import flag [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:
#.........这里部分代码省略.........