How To Use The Connection Manager

<< Back to the SharedPhidgets page

The connection manager object is resposible for establishing the connection to the shared dictionary (in this dictionary, all phidget devices are represented as a model of the distributed Model-View-Controller).
You have to create exact one connection manager object in your project or you can use the ConnectionManagerSkin:

Method 1: Creating object in the code

GroupLab.SharedPhidgets.ConnectionManager connectionManager
  = new GroupLab.SharedPhidgets.ConnectionManager();

Or: If you have created your own class (e.g., main class of the application), just add a private member to the class and create the object in your class constructor:

private GroupLab.SharedPhidgets.ConnectionManager connectionManager;

public Form1()
  this.connectionManager = new GroupLab.SharedPhidgets.ConnectionManager();

Note: you can create more instances of the connection manager, however, all of these managers will control only a single shared dictionary with the SAME address. This is, because the internal connection object is build as Singleton (see: Erich Gamma, Design Patterns) and passes this singleton object to all classes that need a connection.

When you have created the connection manager object, you can simply connect to a Shared Phidgets server by specifying the TCP address (replace localhost with the IP address you want to connect to):

connectionManager.SharedDictionaryURL = "tcp://localhost:sp";

You can disconnect from this server by simply using the closeConnection() method:


In the same way, you can simply connect to another server by changing the SharedDictionaryURL property of the object. The connection manager will then automatically disconnect form the current server and connect to the new server:

connectionManager.SharedDictionaryURL = "tcp://newhost:sp";

Method 2: Creating a ConnectionManagerSkin

1) Select the SharedPhidgets toolbox in Visual Studio, and click on the ConnectioNManagerSkin button.

2) Click on your form and you can see the interface control of the ConnectionManagerSkin. When the application is started, the user can change the IP address and connect.