I'm writing a UDP server/client program in which the server send packets to client through a single port with a fixed window size, and the client will send ack packet back for each packet received. Now I want the server to handle lost packets situation. By some googling, it seems I should use ALARM or SELECT. I certainly don't want to send one packet, wait for ack or timeout, then send another, but SELECT will block the calling function during the timeout, so I think it's not good. ALARM isn't good either since one program can only have one ALARM. So is there any way to allow me to keep tracking timeout for multiple packets server sends?
How to setup timeout for multiple UDP packets in C?
2.3k Views Asked by user1537085 At
2
There are 2 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in UDP
- Discussion on using golang to implement UDP client timeout retransmission
- What is the correct way to setup and use the Ethernet library in Arduino in order to send and receive UDP broadcast messages between LAN devices?
- Multicast packets not received on windows
- Microcontroller hangs with LWIP UDP
- UDP socket client not able to receive data
- "Parameter is not valid" exception when using Image.FromStream() - UDP Video live stream
- k3s change requested UDP port assignment
- Why does the python client socket receiving a reply but still throw the exception in some threadings?
- Gnuradio "double free or corruption (!prev)" error
- Why we need wraparound in UPD checksum algorithm?
- Simple Java UDP server/client-program works on local machine but not over either LAN (different machines) or internet
- Docker bridge does not transmit from tcpreplay IPv6/UDP/GTP traffic
- trying to send TCP packet and recieve it back and count time in client+server app
- recvmsg returns EAGAIN after select reports file descriptor is ready
- Receiving UDP broadcast on Android
Related Questions in TIMEOUT
- MongoDb not connecting C#
- Python Requests: Handling Exceptions and Ensuring Server Response
- Flutter connection to a local api
- SerialPort timeouts in ReadChar() method, WPF, "The operation has timed out."
- test result: Error. Program `sh' timed out (timeout set to 480000ms, elapsed time including timeout handling was 480002ms)
- sql performance in accounting software invoice list
- Scrapy handle closespider timeout in middleware
- Run initialization has timed out after 90.0 sec
- Problem with connection timeout SQL Server
- Connection timeout when trying to reach local web server from within local network
- C# MVC net.7 Application goes in time out
- How to hande nodejs/expressjs gateway timeout by THIRD_PARTY_SERVER?
- Why does the python client socket receiving a reply but still throw the exception in some threadings?
- Timeout error when running webdriverIO project in Docker with MacBook M1 Pro
- mobile devices dont see radio button onchange
Related Questions in ALARM
- Getting Scheduled Alarms from Default Alarm Clock App (specifically Clock on Android)
- flutter_local_notifications is NOT working - zonedSchedule
- How can I make it so other people (and myself) can open the .py file and not have it crash when using mp3 files in the code?
- When we set the alarm, the alarm will run automatically with javascript. without pressing any buttons
- Alarm rules in device profile with Dynamic source type doesn't work?
- How do I create an alarm with nested alarms from 2 arrays
- Alarm BroadcastReceiver is never called
- How to schedule reminder for daily habits
- Unable to start service Intent u=0 not found: AlarmReceiver
- Creating an alarm application using Expo and React Native
- how to add a screen when the screen is off like the default alarm screen when the alarm ring with flutter, alarm screen is not its not coming
- Issue on Android 13 : Android — Repeat notification daily on specific time
- Notification sound never stop when connected to a bluetooth device - Android
- Infinite local notifications for alarm app
- how to kill winsound task after an if condition
Related Questions in SELECT-FUNCTION
- Prevent Tkinter askopenfilenames from ordering files
- How to change the value in a select field in react native
- select() returns 0 immediately on non-blocking AF_PACKET socket ignoring timeval
- select( ) is returning positive value only once
- C - How to cycle a socket
- pthread_create only if data is available on socket
- Breaking out of select for no reason
- C - filling TCP socket send buffer
- Knowing which file-descriptors are ready after select() call in C
- Ping packets on raw sockets
- How to get the interface I am connected to
- Impact of using select with blocking and non-blocking sockets
- Non-blocking connect() and EINTR
- select() times out even though there is data in the buffer
- Is there a Windows equivalent for eventfd?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The following is what comes to my mind first.
Open socket to listen on in non-blocking mode. Non-blocking is key. If select says something is there, but events align just right, it may be a false alarm handled elsewhere and blocking on something that is not coming is trouble.
For each packet sent keep a linked list of sorted by ascending time out times.
As responses are received remove from linked list.
Use select to wait for the next incoming packet with some reasonable time out. I tend to use a maximum of a few seconds even if it looks like a longer time out is reasonable to cover any rare "just in case" situations. What you are blocking on here is incoming packets, but NOT beyond the next time out.
Once the select returns, if requests are available then accept() and process the requests.
Before iterating the loop handle any new time outs, adjusting the linked list as appropriate.
A quick web search turned up more details at http://www.lowtek.com/sockets/select.html.