View Full Version : Sockets help

10-16-2009, 11:49 AM
Hello all,

I have written a socket server and it all works fine but I am now trying to add some error handling.

This is the situation.

Client connects and send data.
Server acknowledges.
If there are commands cued for the client these are sent.
Client acknowledges command has been sent.
Connection is closed.

What I am trying to do is set a timeout on the client acknowledging the command sent. The server listens for the response using the code

$response = socket_recv($tsock, $buf,1024,0);

But if the client doesn't respond I believe that this sits there waiting. So how can I set a timeout on this socket_recv so that the code moves on after a set time of waiting?

Many thanks

10-16-2009, 04:12 PM
Have you set the socket to blocking or non-blocking? A blocked socket will wait for data but a non-blocked socket will return if no data is available. There is also the SO_RCVTIMEO option which should limit the amount of time that is spent waiting.