ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/eg/chat_server
Revision: 1.3
Committed: Fri Aug 7 09:07:37 2009 UTC (14 years, 9 months ago) by elmex
Branch: MAIN
CVS Tags: rel-0_6
Changes since 1.2: +9 -1 lines
Log Message:
changed chat client/server example to the new initialise api and added monitor.

File Contents

# Content
1 #!/opt/bin/perl
2
3 use AnyEvent;
4 use AnyEvent::MP;
5
6 initialise_node "127.0.0.1:1299";
7
8 print "initialized server\n";
9
10 my $chatter_port = port;
11
12 reg $chatter_port, "chatter";
13
14 my %client_ports;
15
16 rcv $chatter_port,
17 join => sub {
18 my ($tag, $client_port) = @_;
19
20 print "got new client port: $client_port\n";
21 $client_ports{$client_port} = 1;
22
23 mon $client_port, sub {
24 my (@reason) = @_;
25 print "client disconnected: " . join (', ', @reason) . "\n";
26 delete $client_ports{$client_port}
27 };
28
29 0
30 },
31 message => sub {
32 my ($tag, $msg) = @_;
33
34 print "message> $msg\n";
35
36 snd $_, message => $msg
37 for keys %client_ports;
38
39 0
40 };
41
42 AnyEvent->condvar->recv;