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