Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > IO::All Socket

Reply
Thread Tools

IO::All Socket

 
 
joe rockhead
Guest
Posts: n/a
 
      10-02-2005

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.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-02-2005
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
 
Reply With Quote
 
 
 
 
joe rockhead
Guest
Posts: n/a
 
      10-02-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57