ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/eg/chat_server
Revision: 1.5
Committed: Fri Aug 14 15:53:56 2009 UTC (14 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-0_7
Changes since 1.4: +1 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 #!/opt/bin/perl
2    
3 root 1.4 use common::sense;
4 elmex 1.1 use AnyEvent::MP;
5    
6 root 1.4 initialise_node;
7 elmex 1.3
8 root 1.4 my %clients;
9 root 1.2
10 root 1.4 sub msg {
11     print "relaying: $_[0]\n";
12     snd $_, $_[0]
13     for values %clients;
14     }
15    
16     sub client_connect {
17     my ($client, $name) = @_;
18    
19     mon $client;
20     mon $client, sub {
21     delete $clients{$client};
22     msg "$name (quits, @_)";
23     };
24 elmex 1.1
25 root 1.4 $clients{$client} = $client;
26 elmex 1.1
27 root 1.4 msg "$name (joins)";
28 elmex 1.3
29 root 1.5 rcv $SELF, sub { msg "$name: $_[0]" };
30 root 1.4 }
31 elmex 1.1
32 root 1.4 warn "server ready.\n";
33 elmex 1.1
34 root 1.4 AE::cv->recv;