IO::All Socket

Discussion in 'Perl Misc' started by joe rockhead, Oct 2, 2005.

  1. joe rockhead

    joe rockhead Guest

    I found IO::All on CPAN.org
    It includes some descriptions on accepting connections on a socket.

    here's what I did with their examples:



    #!/usr/bin/perl

    use IO::All;
    use Perl6::Say;


    say "point A";
    $server = io('10.0.0.123:12345')->fork; # Create a daemon socket
    say "point B \$server = [$server]";
    $connection = $server->accept; # Get a connection socket
    say "point C \$connection = [$connection]";
    $input < $connection; # Get some data from it
    say "point D \$input = [$input]";
    "Thank you!" > $connection; # Thank the caller
    say "point E \$connection = [$connection]";
    $connection->close; # Hang up
    say "point F";
    #io(':6666')->accept->slurp > io->devnull; # Take a complaint and file it
    say "point G";




    running the program, I get up to point B.
    when a connection is made from a remote machine, I get up to point C
    then it just seems to hang there no matter what the remote machine does.
    the remote session seems to just hang also.
    when the remote machine disconnects, I get "Can't open socket" error on the server side.


    right now I just want to be able to accept input and perhaps print something out.
    joe rockhead, Oct 2, 2005
    #1
    1. Advertising

  2. joe rockhead <> wrote in
    news::

    > I found IO::All on CPAN.org
    > It includes some descriptions on accepting connections on a socket.
    >
    > here's what I did with their examples:
    >
    > #!/usr/bin/perl
    >
    > use IO::All;
    > use Perl6::Say;


    You are missing

    use strict;
    use warnings;

    >
    > say "point A";
    > $server = io('10.0.0.123:12345')->fork; # Create a
    > daemon socket say "point B \$server = [$server]";


    I think this creates an implicit while-accept loop around the following
    code.

    > $connection = $server->accept; # Get a connection socket
    > say "point C \$connection = [$connection]";
    > $input < $connection; # Get some data from it


    The server is waiting for *all* the data to be received from the client.

    The only way for that to happen is for the client to somehow signal it
    will not be sending any more data. I don't know how to do that using
    telnet, but in Perl, I would use shutdown. The only way I could do that
    using telnet was to just close the connection.

    > say "point D \$input = [$input]";
    > "Thank you!" > $connection; # Thank the caller


    So, by this time, the connection is closed.

    By the way, if you really like useless right margin comments, at least
    look into Smart::Comments. Note that, although it seemed to work, I was
    getting warnings from it, so it is not used in the code below:

    #!/usr/bin/perl

    use strict;
    use warnings;

    use IO::All;

    warn "### Create server\n";
    my $server = io('127.0.0.1:12345')->fork;
    warn "### Waiting for connection\n";
    my $connection = $server->accept;
    warn "### $connection\n";
    warn "### Reading input\n";
    my $input = $connection->getline;
    warn "### Input = $input\n";
    warn "### Sending response\n";
    $connection->print("Thank you\n");
    warn "### Response sent\n";
    warn "### Closing connection\n";
    $connection->close;
    __END__

    The server won't terminate. I am not sure how to get it to terminate
    after serving one connection. When run, and sent "hello" using telnet,
    the script produces:

    ### IO::All::Socket=GLOB(0x1d03558)
    ### Reading input
    ### Input = hello

    ### Sending response
    ### Response sent
    ### Closing connection

    and I get:

    Thank you

    Connection to host lost.

    In the telnet window.

    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Oct 2, 2005
    #2
    1. Advertising

  3. joe rockhead

    joe rockhead Guest

    hey, man, that's better than mine.
    at least the remote user gets back his prompt.

    I wish I could find more info. google keeps returning copies of cpan's examples on other people's websites.
    joe rockhead, Oct 2, 2005
    #3
    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. Laszlo Nagy
    Replies:
    1
    Views:
    4,761
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    944
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    526
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    644
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    699
Loading...

Share This Page