Perl socket timeout

Discussion in 'Perl Misc' started by mdemmitt@gmail.com, Sep 5, 2006.

  1. Guest

    Hi,
    I am new to perl socket programming. I have written a simple perl
    server. I call:
    $client = $server->accept()

    I want the $client socket to timeout and automatically close after 15
    seconds. Is this possible. I've googled for this, but can't find
    anything specific to my question. Anyone have experience with this.

    -Mike
     
    , Sep 5, 2006
    #1
    1. Advertising

  2. a écrit :
    > Hi,
    > I am new to perl socket programming. I have written a simple perl
    > server. I call:
    > $client = $server->accept()
    >
    > I want the $client socket to timeout and automatically close after 15
    > seconds. Is this possible. I've googled for this, but can't find
    > anything specific to my question. Anyone have experience with this.
    >
    > -Mike
    >

    Hi,

    perldoc -f alarm

    Hope this helps.

    Sebastien
     
    Sébastien Cottalorda, Sep 5, 2006
    #2
    1. Advertising

  3. Guest

    wrote:
    > Hi,
    > I am new to perl socket programming. I have written a simple perl
    > server. I call:
    > $client = $server->accept()
    >
    > I want the $client socket to timeout and automatically close after 15
    > seconds.


    From what you have shown, you are not doing anything with the $client
    connection, so there is nothing to time out. Is it really the accept
    call (on the $server socket) which you wish to timeout?

    > Is this possible. I've googled for this, but can't find
    > anything specific to my question. Anyone have experience with this.


    There is more than one way to do it, and the best way depends on what
    you want to do after timing out. You could use "alarm", or you could
    use IO::Select. (If canread returns the $server socket, then you know you
    can call accept on it without blocking.)

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Sep 5, 2006
    #3
  4. Guest

    wrote:
    > wrote:
    > > Hi,
    > > I am new to perl socket programming. I have written a simple perl
    > > server. I call:
    > > $client = $server->accept()
    > >
    > > I want the $client socket to timeout and automatically close after 15
    > > seconds.

    >
    > From what you have shown, you are not doing anything with the $client
    > connection, so there is nothing to time out. Is it really the accept
    > call (on the $server socket) which you wish to timeout?


    The code above is not all of the code. The line above is used to
    accept an incoming connection. Afterwards, I read from and write to
    $client. Eventually, when the client wants the server to close the
    connection it sends a specific token, let's say the token is "END". I
    want to account for the possibility of the client machine crashing or
    failing to send END. To account for these possibilities, I want $client
    to automatically close 15 seconds after it has been opened. Is this
    possible? I will look into alarm and see if there is a way I can use
    that to replicate the functionality I am looking for. It would be
    nice, however, to be able to set some timeout value for a client
    socket.

    Thanks,
    Mike
    >
    > > Is this possible. I've googled for this, but can't find
    > > anything specific to my question. Anyone have experience with this.

    >
    > There is more than one way to do it, and the best way depends on what
    > you want to do after timing out. You could use "alarm", or you could
    > use IO::Select. (If canread returns the $server socket, then you know you
    > can call accept on it without blocking.)
    >
    > Xho
    >
    > --
    > -------------------- http://NewsReader.Com/ --------------------
    > Usenet Newsgroup Service $9.95/Month 30GB
     
    , Sep 5, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. p.
    Replies:
    4
    Views:
    598
    Giampaolo Rodola'
    Jan 10, 2009
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,861
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    974
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    555
    Laszlo Nagy
    Feb 1, 2009
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,296
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page