ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/eg/chat_server
Revision: 1.1
Committed: Mon Aug 3 09:43:15 2009 UTC (14 years, 10 months ago) by elmex
Branch: MAIN
Log Message:
added examples from intro.

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use AnyEvent;
3 use AnyEvent::MP;
4
5 become_public "localhost:1299";
6
7 my $chatter_port = create_port;
8 $chatter_port->register ("chatter");
9
10 my %client_ports;
11
12 $chatter_port->rcv (join => sub {
13 my ($chatter_port, $type, $client_port) = @_;
14
15 print "got new client port: $client_port\n";
16
17 $client_ports{$client_port} = 1;
18 0
19 });
20
21 $chatter_port->rcv (message => sub {
22 my ($chatter_port, $type, $msg) = @_;
23
24 print "message> $msg\n";
25
26 snd $_, message => $msg for keys %client_ports;
27 0
28 });
29
30 AnyEvent->condvar->recv;
31