… | |
… | |
211 | the sender and one for the receiver. First the receiver application, in |
211 | the sender and one for the receiver. First the receiver application, in |
212 | full: |
212 | full: |
213 | |
213 | |
214 | use AnyEvent; |
214 | use AnyEvent; |
215 | use AnyEvent::MP; |
215 | use AnyEvent::MP; |
216 | use AnyEvent::MP::Global; |
|
|
217 | |
216 | |
218 | configure nodeid => "eg_receiver", binds => ["*:4040"]; |
217 | configure nodeid => "eg_receiver/%u", binds => ["*:4040"]; |
219 | |
218 | |
220 | my $port = port; |
219 | my $port = port; |
221 | |
|
|
222 | grp_reg eg_receivers => $port; |
220 | my $db_guard = db_reg eg_receivers => $port; |
223 | |
221 | |
224 | rcv $port, test => sub { |
222 | rcv $port, test => sub { |
225 | my ($data, $reply_port) = @_; |
223 | my ($data, $reply_port) = @_; |
226 | |
224 | |
227 | print "Received data: " . $data . "\n"; |
225 | print "Received data: " . $data . "\n"; |
… | |
… | |
356 | talking about the receiver. |
354 | talking about the receiver. |
357 | |
355 | |
358 | Let's look at the next line(s): |
356 | Let's look at the next line(s): |
359 | |
357 | |
360 | my $port = port; |
358 | my $port = port; |
361 | grp_reg eg_receivers => $port; |
359 | my $db_guard = db_reg eg_receivers => $port; |
362 | |
360 | |
363 | The C<port> function has already been discussed. It simply creates a new |
361 | The C<port> function has already been discussed. It simply creates a new |
364 | I<port> and returns the I<port ID>. The C<grp_reg> function, however, is |
362 | I<port> and returns the I<port ID>. The C<grp_reg> function, however, is |
365 | new: The first argument is the name of a I<global group>, and the second |
363 | new: The first argument is the name of a I<global group>, and the second |
366 | argument is the I<port ID> to register in that group. |
364 | argument is the I<port ID> to register in that group. |
… | |
… | |
384 | |
382 | |
385 | Ok, now let's take a look at the sender code: |
383 | Ok, now let's take a look at the sender code: |
386 | |
384 | |
387 | use AnyEvent; |
385 | use AnyEvent; |
388 | use AnyEvent::MP; |
386 | use AnyEvent::MP; |
389 | use AnyEvent::MP::Global; |
|
|
390 | |
387 | |
391 | configure nodeid => "eg_sender", seeds => ["*:4040"]; |
388 | configure nodeid => "eg_sender/%u", seeds => ["*:4040"]; |
392 | |
389 | |
393 | my $find_timer = |
390 | my $find_timer = |
394 | AnyEvent->timer (after => 0, interval => 1, cb => sub { |
391 | AnyEvent->timer (after => 0, interval => 1, cb => sub { |
395 | my $ports = grp_get "eg_receivers" |
392 | my $ports = grp_get "eg_receivers" |
396 | or return; |
393 | or return; |