How do I cause a message to be dropped after 1 second? (UDP client/server in C)

65 Views Asked by At

I have a UDP client based off of http://cs.baylor.edu/~donahoo/practical/CSockets/code/UDPEchoClient.c where the client sends a message and the server echos it back. I have a configurable server where I can drop packets, and I am sending multiple messages instead of just 1 in the code linked above. How do I make the message drop if it takes more than 1 second? As of right now, I am checking each message after I get it in recvfrom(), but I want my whole program to run in under ~1.5s because I do not want to wait 1 second for each message (this would take forever if there were a lot of messages). Is there a way to attach like a timer or something to each message so that it considers itself dropped if its not received within 1 second? Thanks!

1

There are 1 best solutions below

1
On

Use TTL for UDP packets

int ttl = 60; /* max = 255 */
setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));