Reputation: 115
I wish to keep polling a server, and switch to this server(sending data to this server over TCP/IP) when it becomes available.
Any suggestion to do this in C.
Thanks,
Upvotes: 1
Views: 155
Reputation: 215277
How do you determine if you have permissions to open a file? Try to open it.
How do you determine if the disk is full? Try to write to it.
How do you determine if a port is already taken? Try to bind to it.
How do you determine if a mutex is unlocked? Try to lock it.
How do you determine if a tcp server is accepting connections? Try to connect to it.
There's a reason to the pattern: in all these cases, any test in advance would be meaningless because the result might change between the time you test and the time you try to use the result of the test. So when you want to do something, try it, and make sure your code properly handles both success and failure of the operation.
Upvotes: 6