I have client code which gets a response from the server using UDP and recvfrom(). This is working fine when the server is ON, but once I stop the server my client program is hanging; I suspect recvfrom() is waiting for the response from the server.
If the server and client are both are installed on same system them I am getting error from recvfrom() when the server is OFF, but when the server and client are on different systems then the client hangs at recvfrom() as there is no response from the server since its OFF.
Please some one can give me idea how can I can deal with this situation, maybe a timer signal interuption can solve the issue.. can anyone throw some light on this?
I am Using Visual studio 2005.
Your call is blocking, because there is no data for this socket right now. When the server was on, it was fast enough to send data so the
recvfromcall got it and returned quickly. When the server is off, nobody’s sending data andrecvfromwaits forever. It does not matter whether server is on or off,recvfromis doing the same thing in both cases; you just don’t notice the delay in the first case.You need to use non-blocking sockets. In non-blocking mode,
recvfromwill return an error when there is no data, instead of waiting. You can then useselectcall to sleep until a timeout happens or the data arrive.