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!
Asked
Active
Viewed 60 times
0
-
So, you want the *server* to drop a message if `recvfrom()` does not retrieve it from the kernel's incoming queue within 1 second of receipt? The OS does not provide that functionality. If a packet is placed into the queue, it stays in the queue until read. If the queue fills up because `recvfrom()` is not being called often enough, *subsequent* packets will be dropped automatically until space in the queue clears up. If this is not what you want, call `recvfrom()` more often (like in a dedicated thread) and manage your own list of items, then you can put timers on your list items as needed. – Remy Lebeau Feb 07 '16 at 21:04
1 Answers
-1
Use TTL for UDP packets
int ttl = 60; /* max = 255 */
setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));

agent420
- 3,291
- 20
- 27
-
1This won't help. TTL would be more accurately called 'hop limit', and it is not in the least related to time. – Joel C Feb 07 '16 at 20:56