default socket blocks. To control this action, use the funcitons socket setblocking () or settimeout ().
if you want to make your own time.
mysocket.setblocking(0)
ACK, address = mysocket.recvfrom(1024)
but I would do something like
import socket
mysocket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
mysocket.settimeout(0.5)
dest = ('127.0.0.01', 88)
user_input = raw_input()
while user_input:
mysocket.sendto(user_input, dest)
acknowledged = False
while not acknowledged:
try:
ACK, address = mysocket.recvfrom(1024)
acknowledged = True
except socket.timeout:
mysocket.sendto(user_input, dest)
print ACK
user_input = raw_input()
mysocket.close()
source
share