Tutorial by Caitlin MacFadyen

In this example, there is the Seller, the first buyer (Buyer1) and the second buyer (Buyer2). The scenario is that Buyer1 sends the title of the book they wish to purchase to the Seller, who returns its price. Buyer1 cannot afford the book alone, so sends a quote to Buyer2 who will potentially pay a portion of the cost. There is a choice in Buyer2’s protocol specification as they decide whether to agree to send the quoted payment to the Seller. If Buyer2 agrees, they send a String confirming their agreement to both other participants. Then Buyer1 sends their part-payment to the Seller, and Buyer2 follows with the rest of the payment. If they quit, a quit message is sent to Buyer1 and Seller respectively. Recursion is defined by the rec X {… continue X} statement around the body of the protocol. The choice at role C requires the user to choose between the enumerations ADD and BYE. If ADD is chosen, the two integers are sent to S and the result of the addition is sent back. When continue X is reached, the protocol loops back to rec X and asks the user to choose again. This continues indefinitely until BYE is chosen, whereupon the Bye() method is called and the protocol terminates.