… | |
… | |
235 | |
235 | |
236 | First let's have a look at C<configure>: |
236 | First let's have a look at C<configure>: |
237 | |
237 | |
238 | configure nodeid => "eg_receiver/%u", binds => ["*:4040"]; |
238 | configure nodeid => "eg_receiver/%u", binds => ["*:4040"]; |
239 | |
239 | |
240 | Before we are able to send messages to other nodes we have to initialise |
240 | Before we are able to send messages to other nodes we have to configure |
241 | ourself to become a "distributed node". Initialising a node means naming |
241 | the node to become a "networked node". Configuring a node means naming |
242 | the node and binding some TCP listeners so that other nodes can |
242 | the node and binding some TCP listeners so that other nodes can contact |
243 | contact it. |
243 | it. The choice on whether a process becomes a networked node or not must |
|
|
244 | be done before doing anything else with AnyEvent::MP. |
244 | |
245 | |
245 | Additionally, to actually link all nodes in a network together, you can |
246 | Additionally, to actually link all nodes in a network together, you should |
246 | specify a number of seed addresses, which will be used by the node to |
247 | specify a number of seed addresses, which will be used by the node to |
247 | connect itself into an existing network, as we will see shortly. |
248 | connect itself into an existing network, as we will see shortly. |
248 | |
249 | |
249 | All of this (and more) can be passed to the C<configure> function - later |
250 | All of this info (and more) can be passed to the C<configure> function - |
250 | we will see how we can do all this without even passing anything to |
251 | later we will see how we can do all this without even passing anything to |
251 | C<configure>! |
252 | C<configure>! |
252 | |
253 | |
253 | The first parameter, C<nodeid>, specified the node ID (in this case |
254 | Back to the function call in the program: the first parameter, C<nodeid>, |
254 | C<eg_receiver/%u> - the default is to use the node name of the current |
255 | specified the node ID (in this case C<eg_receiver/%u> - the default is to |
255 | host plus C</%u>, which goves the node a name with a random suffix to |
256 | use the node name of the current host plus C</%u>, which goves the node a |
256 | make it unique, but for this example we want the node to have a bit more |
257 | name with a random suffix to make it unique, but for this example we want |
257 | personality, and name it C<eg_receiver> with a random suffix. |
258 | the node to have a bit more personality, and name it C<eg_receiver> with a |
|
|
259 | random suffix. |
258 | |
260 | |
259 | Why the random suffix? Node IDs need to be unique within the network and |
261 | Why the random suffix? Node IDs need to be unique within the network and |
260 | appending a random suffix is the easiest way to do that. |
262 | appending a random suffix is the easiest way to do that. |
261 | |
263 | |
262 | The second parameter, C<binds>, specifies a list of C<address:port> pairs |
264 | The second parameter, C<binds>, specifies a list of C<address:port> pairs |