-module(checker). -export([start/2]). %% This is the loop that keeps getting numbers, and checking them on a node. %% Ask the counter for a new number to check start(Counter, Node) -> Counter ! {self(), next}, receive {nextnumber, ToCheck} -> check(Node, ToCheck, Counter); Other -> io:format("Counter returned ~w~n", [Other]) end. %% Check the given number on the given Node check(Node, ToCheck, Counter) -> case rpc:call(Node, is_prime, is_prime, [ToCheck]) of false -> io:format("."), start(Counter, Node); true -> io:format("~n~w has found that ~w is a prime!~n", [Node, ToCheck]), start(Counter, Node); {badrpc,nodedown} -> io:format("~n~w has disappeared~n", [Node]); {badrpc,{'EXIT',{undef,[{is_prime,is_prime,[_]},{rpc,'-handle_call/3-fun-0-',5}]}}} -> io:format("~n~w doesn't have is_prime:is_prime/1~n", [Node]); Any -> io:format("~nUnknown value in checker: ~w~n", [Any]) end.