Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Sockets help

  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Sockets help

    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

    PHP Code:
    $response socket_recv($tsock$buf,1024,0);
    $respdata.=$buf
    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
    Scott
    Last edited by agravayne; 10-16-2009 at 11:57 AM.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,303
    Thanks
    4
    Thanked 204 Times in 201 Posts
    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.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •