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