joe rockhead <> wrote in
news:aeudnWM-3bo2dqLeRVn-:
> 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(0x1d0355

### 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/cl...uidelines.html