Handling timeout in network application
Posted
by
user2175831
on Programmers
See other posts from Programmers
or by user2175831
Published on 2013-03-27T21:21:55Z
Indexed on
2013/10/22
4:07 UTC
Read the original article
Hit count: 155
How can I handle timeouts in a network application.
I'm implementing a provisioning system on a Linux server, the code is huge so I'm going to put the algorithm, it works as like this
- Read provisioning commands from file
- Send it to another server using TCP
- Save the request in hash.
- Receive the response then
- if successful response received then remove request from hash
- if failed response received then retry the message
The problem I'm in now is when the program didn't receive the response for a timeout reason then the request will be waiting for a response forever and won't be retried.
And please note that I'll be sending hundreds of commands and I have to monitor the timeout commands for all of them.
I tried to use timer but that didn't help because I'll end up with so many waiting timers and I'm not sure if this is a good way of doing this.
The question is how can I save the message in some data structure and check to remove or retry it later when there is no response from the other end?
Please note that I'm willing to change the algorithm to anything you suggest that could deal with the timeouts.
© Programmers or respective owner