ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/listen
Revision: 1.3
Committed: Sat May 24 23:34:28 2008 UTC (16 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-4_151, rel-4_152, rel-4_91, rel-4_04, rel-4_23, rel-7_05, rel-4_21, rel-7_07, rel-7_01, rel-7_02, rel-7_03, rel-7_08, rel-7_09, rel-4_412, rel-4_81, rel-4_83, rel-4_82, rel-4_86, rel-4_352, rel-5_112, rel-4_351, rel-7_16, rel-4_14, rel-4_15, rel-7_13, rel-4_13, rel-7_11, rel-5_251, rel-0_85, rel-4_331, rel-6_0, rel-6_1, rel-4_231, rel-4_233, rel-4_232, rel-4_8, rel-4_234, rel-4_4, rel-6_11, rel-6_12, rel-6_13, rel-5_261, rel-4_05, rel-7_15, rel-7_14, rel-4_12, rel-7_12, rel-4_11, rel-6_02, rel-6_01, rel-5_271, rel-5_28, rel-5_29, rel-7_0, rel-5_21, rel-5_22, rel-5_23, rel-5_24, rel-5_26, rel-5_27, rel-5_1, rel-5_0, rel-5_3, rel-5_2, rel-7_04, rel-4_22, rel-5_201, rel-5_202, rel-5_31, rel-4_161, rel-4_160, rel-5_111, rel-4_881, rel-4_411, rel-4_9, rel-5_01, rel-6_14, rel-4_45, rel-4_41, rel-4_42, rel-4_1, rel-4_2, rel-4_88, rel-4_3, rel-5_11, rel-5_12, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35, rel-4_03, HEAD
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use strict;
3 use Socket;
4 use IO::Socket::INET;
5 use AnyEvent::Socket;
6 use AnyEvent::Handle;
7
8 my $cv = AnyEvent->condvar;
9
10 my $hdl;
11
12 warn "listening on port 34832...\n";
13
14 AnyEvent::Socket::tcp_server undef, 34832, sub {
15 my ($clsock, $host, $port) = @_;
16 print "Got new client connection: $host:$port\n";
17
18 $hdl =
19 AnyEvent::Handle->new (
20 fh => $clsock,
21 on_eof => sub { print "client connection $host:$port: eof\n" },
22 on_error => sub { print "Client connection error: $host:$port: $!\n" }
23 );
24
25 $hdl->push_write ("Hello!\015\012");
26
27 $hdl->push_read (line => sub {
28 my (undef, $line) = @_;
29 print "Yay, got line: $line\n";
30 $hdl->push_write ("Bye\015\012");
31 $hdl->on_drain (sub { $hdl->fh->close; undef $hdl });
32 });
33 };
34
35 $cv->wait;