Skip to content

Networked Examples

Shane McLean edited this page Oct 13, 2017 · 4 revisions

This section contains some basic examples, covering usage of the tuple space as a networked data structure and agents as lightweight processes that access the shared resource.

Getting started

The projecs use the nuget packages. Please update the dotSpace libraries to the latest version. Please note that the compiled versions might not run using mono, and running on Mac or Linux might require additional setup (See below).


Example5 - Hello

This Example show how to setup a networked application using a SpaceRepository and a RemoteSpace. The agent then obtains access to the space through a connection.
The initialization and startup is done in Main.cs, while the Student.cs is the agent accessing the shared resource.

Syntax

  • Using .NET type the following in the command line: Example5.exe <param>.
  • Using Mono type the following in the command line: mono Example5.exe <param>.


where <param> is a any name.


Running the program with the following parameters:

Example5.exe Turing

will give the following output:

Hello student!
Turing, you are attending course 02148

Example6 - Dining Philosophers

This Example show how to implement a solution to the Dining philosophers problem.
The initialization and startup is done in Main.cs, while the Philosopher.cs is the philosophers/agents struggling to eat the spaghetti only using their forks. In this example, the agents are struggling to obtain access to the shared resources over a persistent tcp connection. All agents share the same connection in this example.

Syntax

  • Using .NET type the following in the command line: Example6.exe <param>.
  • Using Mono type the following in the command line: mono Example6.exe <param>.


where <param> is either 'table' or 'philosopher'


Running the programs in each console:

Example6.exe table
Example6.exe philosopher

will give the following output:

...
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Homer: I AM EATING WITH BOTH MY HANDS: 5
Done eating: 5
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Homer: I AM EATING WITH BOTH MY HANDS: 5
Done eating: 5
Done eating: 3
Bob: I AM EATING WITH BOTH MY HANDS: 3
Done eating: 3
Alice: I AM EATING WITH BOTH MY HANDS: 1
Done eating: 1
Alice: I AM EATING WITH BOTH MY HANDS: 1
Dave: I AM EATING WITH BOTH MY HANDS: 4
Done eating: 4
...

Example7 - Ping Pong

This Example shows how to pass a tuple back and forth between two agents. In this case the tuple holds the string value "ping" or "pong" and the number of times the tuple has been exchanged.
The initialization and startup is done in Main.cs, while the PingPong.cs is the agent passing the message back and forth. In this example the agents do not share the same tcp connection, but have an individual persistent tcp connection.

Syntax

  • Using .NET type the following in the command line: Example7.exe.
  • Using Mono type the following in the command line: mono Example7.exe.


Running the program with the following parameters:

Example7.exe

will give the following output:

<pong,1>
<ping,2>
<pong,3>
<ping,4>
<pong,5>
<ping,6>
<pong,7>
<ping,8>
<pong,9>
<ping,10>
<pong,11>
<ping,12>
<pong,13>
<ping,14>
<pong,15>
<ping,16>
...

Example8 - Producer Consumer

This Example show how to implement a networked producer and consumer agent.
The initialization and startup is done in Main.cs.forth. The program implements one producer agent in Producer.cs, and three types of consumer agents in Food.cs, Drug.cs and Any.cs. All the agents in this example share the same RemoteSpace, but connections are created for each request. See ConnectionMode for a description of the different connections modes.

Syntax

  • Using .NET type the following in the command line: Example8.exe <param>.
  • Using Mono type the following in the command line: mono Example8.exe <param>.


where <param> is either 'producer' or 'consumer'


Running the programs in each console:

Example8.exe producer
Example8.exe consumer

will give the following output:

Alice adding items to the grocery list...
Alice adding milk(1)
Alice adding soap(2)
Alice adding butter(3)
Dave shopping 2 units of soap...
GOING SHOPPING:
Bob shopping 1 units of milk...
Bob shopping 3 units of butter...