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. Advertising

  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. 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. jeff
    Replies:
    0
    Views:
    1,533
  2. Rick
    Replies:
    0
    Views:
    1,169
  3. Gaurav Khanna [.NET MVP]

    Re: System.Net.Sockets.Tcplistener

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

    UNIX Domain Sockets

    Didatus, Aug 18, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,562
  5. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,187
    Iceberg
    Sep 6, 2003
Loading...

Share This Page