0

I have a UDP client that send a number of packets to a server, I need to set a period of time between every packet, in other words I want to control the sending time of each packet.

How can I dot it? Help!

2
  • Is this what you're looking for? gnu.org/software/libc/manual/html_node/Sleeping.html Commented Sep 19, 2013 at 22:11
  • not need really to a sleep function to set a sending timing ? I need to set a fixed "sending time" between packets as variable or parameter in my program. (i.e) let say I'll send 10 packets: I want to fix for example a period of 10 seconds between sending each packet. Commented Sep 19, 2013 at 22:43

1 Answer 1

1

You cannot ask the socket to send the data at a certain point in time. All control you have about the sending time is by not calling send/sendto() until you want the sending to happen - even then, the TCP/IP stack is free to delay the actual packet sending, so you can only hope for the best. Basically, you get the current time from the OS, put the packet into the socket to be sent, sleep until the next packet is due, put the next packet into the socket, and so on.

Sign up to request clarification or add additional context in comments.

1 Comment

OK thanks for the explanation, you were absolutely rigth saying that I cannot ask the socket to send the Data, so the sleep is the best way, eventuelly nanosleep() method

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.