ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/connect
Revision: 1.2
Committed: Sat May 24 17:06:10 2008 UTC (16 years, 1 month ago) by elmex
Branch: MAIN
CVS Tags: rel-4_0
Changes since 1.1: +9 -15 lines
Log Message:
updated examples

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use IO::Socket::INET;
3 use AnyEvent::Socket;
4 use AnyEvent::Handle;
5
6 my $cv = AnyEvent->condvar;
7
8 my $hdl;
9
10 my $watchobj = AnyEvent::Socket::tcp_connect ("www.google.com", 80, sub {
11 my ($sock) = @_;
12
13 unless ($sock) {
14 warn "couldn't connect: $!";
15 return;
16 }
17
18 $hdl =
19 AnyEvent::Handle->new (
20 fh => $sock,
21 on_eof => sub { print "received eof\n"; undef $hdl }
22 );
23
24 $hdl->push_write ("GET / HTTP/1.0\015\012\015\012");
25
26 $hdl->push_read_line (sub {
27 my ($hdl, $line) = @_;
28 print "Yay, got line: $line\n";
29 $cv->broadcast;
30 });
31
32 }, sub {
33 10 # the timeout
34 });
35
36 $cv->wait;