Create a blocking and timeout client

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    Create a blocking and timeout client

    The client program I tried to create will send some message to another
    program on a different server and block wait for reply message. If
    connection is timeout, close the socket.

    I did something like

    $socket = socket_create (AF_INET, SOCK_STREAM, 0);

    if (!socket_set_bl ock($socket)) { // $socket is now blocking
    echo socket_strerror (socket_last_er ror());
    }

    $time_soc = array("sec"=>10 , "usec"=>0);
    if (!socket_set_op tion($socket, SOL_SOCKET, SO_RCVTIMEO, $time_soc))
    {
    die("error message is:
    ".socket_strerr or(socket_last_ error($socket)) );
    }

    Is this the right way to do it? PHP fails at socket_set_opti on. Thanks
  • Mike

    #2
    Re: Create a blocking and timeout client

    Anyone has any idea?

    michma@gmail.co m (Mike) wrote in message news:<8e9b7c06. 0409211906.84ad 3c4@posting.goo gle.com>...[color=blue]
    > The client program I tried to create will send some message to another
    > program on a different server and block wait for reply message. If
    > connection is timeout, close the socket.
    >
    > I did something like
    >
    > $socket = socket_create (AF_INET, SOCK_STREAM, 0);
    >
    > if (!socket_set_bl ock($socket)) { // $socket is now blocking
    > echo socket_strerror (socket_last_er ror());
    > }
    >
    > $time_soc = array("sec"=>10 , "usec"=>0);
    > if (!socket_set_op tion($socket, SOL_SOCKET, SO_RCVTIMEO, $time_soc))
    > {
    > die("error message is:
    > ".socket_strerr or(socket_last_ error($socket)) );
    > }
    >
    > Is this the right way to do it? PHP fails at socket_set_opti on. Thanks[/color]

    Comment

    Working...