本文整理汇总了Python中Network.l3_recvfrom方法的典型用法代码示例。如果您正苦于以下问题:Python Network.l3_recvfrom方法的具体用法?Python Network.l3_recvfrom怎么用?Python Network.l3_recvfrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network.l3_recvfrom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: import Network [as 别名]
# 或者: from Network import l3_recvfrom [as 别名]
def handle(self):
global mynode, link1_port, link2_port, link1_flag, link2_flag
data = self.request[0].strip()
#socket = self.request[1]
# set message and split
message = data
message = message.split()
# look for 'hello' message
if message[0] == "hhhhh":
# set link flags
if message[1] == link1_port:
link1_flag = True
if message[1] == link2_port:
link2_flag = True
# not hello, forward to network layer
else:
Network.l3_recvfrom(mynode, data)
示例2: l2_recvfrom
# 需要导入模块: import Network [as 别名]
# 或者: from Network import l3_recvfrom [as 别名]
def l2_recvfrom (client_socket=None, node=None):
"""
This function will be used in Layer 3, the Network layer. Nowhere in this Layer 2
is this function used--rather, this layer purely uses good ol' UDP recvfrom.
"""
while 1:
data = ''.encode()
buffer = ''.encode()
# Read a bunch of bytes up to the MTU or length of data.
while len(data) <= 4096:
buffer, external_address = client_socket.recvfrom(4096-len(data))
if buffer:
data += buffer
else:
#thread.interrupt_main()
break
# This is our protocol. Stop reading when we see \r\n.
if '\r\n'.encode() in buffer:
#thread.interrupt_main()
break
# Split the headers.
packet = data.decode().split('@@')
frame_header = packet[0].split('@')
datagram_header = packet[1].split('@')
# Now we should have something like [Frame, Datagram, Segment].
# Step 1. Build a new Frame.
frame = Frame(frame_header[2], int(frame_header[3]), frame_header[0], int(frame_header[1]),
int(frame_header[4]), packet[1])
# Step 2. Build a new Datagram so we can pass it to l3_recvfrom().
# The order goes 6, 7, then 4, 5 because 6/7 is the destination of this packet, which is
# destined for where the source is. It's backwards since we are receiving, not sending.
datagram = Network.Datagram(int(datagram_header[0]), int(datagram_header[1]), int(datagram_header[2]),
int(datagram_header[3]), int(datagram_header[6]), int(datagram_header[7]),
int(datagram_header[4]), int(datagram_header[5]), int(datagram_header[8]),
packet[2])
# l3_recvfrom will return something, but right now, we are not storing that value yet.
#NetworkLayer.l3_recvfrom(datagram)
return len(buffer), frame, datagram, external_address, \
Network.l3_recvfrom(client_socket, str(packet[1]+'@@'+packet[2]), node)