IO::All Socket

J

joe rockhead

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

A. Sinan Unur

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
 
J

joe rockhead

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top