Skip to content

Commit

Permalink
start of 17sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
stmuk committed Apr 16, 2015
1 parent 974e959 commit ece01d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions categories/cookbook/17sockets/17-01tcp_client.pl
@@ -0,0 +1,18 @@
use v6;

=begin pod
=head1 Writing a TCP Client
You want to connect to a socket on a remote host
=end pod

my $s = IO::Socket::INET.new( :host<www.perl6.org>, :port(80) );
$s.send( "HEAD / HTTP/1.0\n\n" );

while ( my $r = $s.get ) {
say $r;
}


# vim: expandtab shiftwidth=4 ft=perl6
17 changes: 17 additions & 0 deletions categories/cookbook/17sockets/17-02tcp_server.pl
@@ -0,0 +1,17 @@
use v6;

=begin pod
=head1 Writing a TCP Server
You want to write a TCP Server to listen on a socket
=end pod

my $s = IO::Socket::INET.new( :localport(1024), :type(1), :reuse(1),
:listen(10));

while ( my $c = $s.accept() ) {
say $c.get;
}

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit ece01d9

Please sign in to comment.