ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/eg/chat_client
Revision: 1.11
Committed: Mon Aug 31 13:18:06 2009 UTC (17 years ago) by root
Branch: MAIN
CVS Tags: rel-0_95, rel-1_0
Changes since 1.10: +2 -5 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 #!/opt/bin/perl
2    
3 root 1.8 # Usage: ./chat_client nickname optional-servername
4     # implement a chat client using "traditional message passing"
5    
6 root 1.4 use common::sense;
7 elmex 1.1 use AnyEvent::MP;
8 root 1.6 use AnyEvent::MP::Global;
9 elmex 1.1
10 root 1.9 my $nick = shift;
11 elmex 1.1
12 root 1.11 configure;
13 elmex 1.3
14 root 1.4 $| = 1;
15 elmex 1.3
16 root 1.4 my ($client, $server);
17 elmex 1.1
18 root 1.4 sub server_connect {
19 root 1.7 my $servernodes = AnyEvent::MP::Global::find "eg_chat_server"
20     or return after 1, \&server_connect;
21 elmex 1.1
22 root 1.7 print "\rconnecting...\n";
23    
24     $client = port { print "\r \r@_\n> " };
25     mon $client, sub {
26     print "\rdisconnected @_\n";
27     &server_connect;
28     };
29    
30 root 1.11 $server = $servernodes->[0];
31 root 1.8 snd $server, join => $client, $nick;
32 root 1.7 mon $server, $client;
33 root 1.4 }
34 elmex 1.1
35 root 1.4 server_connect;
36 elmex 1.1
37 root 1.4 my $w = AE::io 0, 0, sub {
38     chomp (my $line = <STDIN>);
39     print "> ";
40 root 1.8 snd $server, privmsg => $nick, $line
41     if $server;
42 root 1.2 };
43 elmex 1.1
44 root 1.4 print "> ";
45     AE::cv->recv;
46 elmex 1.1