I wrote a udp server and client. The client send simple udp messages to the server and the server will respond. The server will randomly drop some response packets. In my client side code, I wrote the following line
for i in range(0,10):
sequence_number = i
start = time.time()
clientSocket.sendto("Ping " + str(i) + " " + str(start), server)
# Receive the client packet along with the address it is coming from
message, address = clientSocket.recvfrom(1024)
end = time.time()
if message != '':
print message
rtt = end - start
print "RTT = " + str(rtt)
The following line stuck there if the server drop the response.
message, address = clientSocket.recvfrom(1024)
I tried the timeout method here:
Socket recv - limited wait time
But the timeout will abort the whole client program. I just want the client to wait for 5 second and then continue to send the next packet if the last response is not received (dropped by the server).
How can I set a wait time in the client?