sockets

Discussion in 'Perl Misc' started by someone, Jan 18, 2004.

  1. someone

    someone Guest

    is there a way i can check whether there is any data in a tcp socket and to
    check whether the socket has closed or not

    for example

    $line = <SOCKET>;

    if the party at the other end does not send data, then the program will hang
    at this point until data arrives. if there is data, how to know the size? i
    want to read whatever that is available.
     
    someone, Jan 18, 2004
    #1
    1. Advertisements

  2. someone

    Rocco Caputo Guest

    On Sun, 18 Jan 2004 20:41:04 +0800, someone wrote:
    > is there a way i can check whether there is any data in a tcp socket and to
    > check whether the socket has closed or not
    >
    > for example
    >
    > $line = <SOCKET>;
    >
    > if the party at the other end does not send data, then the program will hang
    > at this point until data arrives. if there is data, how to know the size? i
    > want to read whatever that is available.


    The select() function, conveniently wrapped by the IO::Select module,
    will let you wait for data on a socket without necessarily blocking.

    sysread() will read whatever is available on the socket, up to a
    specified limit.

    If you want input by lines, you will need to gather data in a buffer and
    find the newlines therein. Buffered I/O like <SOCKET> is not compatible
    with select(), and the documentation for select() will mention this.

    See:

    perldoc IO::Select
    perldoc -f sysread
    perldoc -f syswrite
    perldoc -f select
    _Perl Cookbook_ (which has good examples of these things)

    --
    Rocco Caputo - - http://poe.perl.org/
     
    Rocco Caputo, Jan 18, 2004
    #2
    1. Advertisements

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. Gaurav Khanna [.NET MVP]

    Re: System.Net.Sockets.Tcplistener

    Gaurav Khanna [.NET MVP], Jul 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,612
    Gaurav Khanna [.NET MVP]
    Jul 25, 2003
  2. Didatus

    UNIX Domain Sockets

    Didatus, Aug 18, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,676
  3. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,298
    Iceberg
    Sep 6, 2003
  4. Jim Kipp
    Replies:
    1
    Views:
    1,297
    Jim Gibson
    Feb 12, 2004
  5. VincentWong
    Replies:
    1
    Views:
    843
    VincentWong
    Dec 29, 2003
  6. Torsten Brasch
    Replies:
    5
    Views:
    6,655
    Feroze [MSFT]
    Jan 7, 2004
  7. SOS

    Sockets

    SOS, Feb 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    583
    Eric Lawrence [MSFT]
    Feb 29, 2004
  8. =?Utf-8?B?U3llZCBBdW4gQWxp?=

    how to communicate server/client using tcpip and /or sockets

    =?Utf-8?B?U3llZCBBdW4gQWxp?=, Aug 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    629
    Steve C. Orr [MVP, MCSD]
    Aug 7, 2004
Loading...