我正在尝试实现一个停止等待算法。我在发送者处执行超时时遇到问题。在等待recier的ACK时,我正在使用recvfrom()函数。但是这使得程序空闲,我不能跟随超时来重新传输。
这是我的代码:
import socket
import time
mysocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
while True:
ACK= " "
userIn=raw_input()
if not userIn : break
mysocket.sendto(userIn, ('127.0.0.01', 88))
ACK, address = mysocket.recvfrom(1024) #the prog. is idle waiting for ACK
future=time.time()+0.5
while True:
if time.time() > future:
mysocket.sendto(userIn, ('127.0.0.01', 88))
future=time.time()+0.5
if (ACK!=" "):
print ACK
break
mysocket.close()
默认情况下,套接字块。使用套接字函数setblocking()或settimeout()来控制此行为。
如果你想做你自己的时机。
但我会做些
相关问题 更多 >
编程相关推荐