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