C# Client


  • .NET Framework 4.5
  • App created in VS2012, can be openned with VS2013

Getting the files:

  1. Create a new project in your IDE (such as Visual Studio).
  2. In your project folder, clone the repository recursively:
    • git clone --recursive https://github.com/ase-lab/SoD_CS_Library.git SOD
    • This will clone SOD library, as well as its dependency - socketIOclient

Setting up your solution and references:

  1. Right-click your solution in Solution Explorer, and choose Add... Existing Project.
  2. Add the SOD library and socketIOclient projects:
    • \SoD_CS_Library\SOD_CS_Library\SOD_CS_Library\SOD_CS_Library.csproj
    • \SoD_CS_Library\SOD_CS_Library\socketIOclient\SocketIO\SocketIOClient.csproj
  3. Right-click your solution in Solution Explorer, and choose Manage NuGet Packages for Solution.
    • Also suggest to Enable NuGet Package Restore
    • Make sure Newtonsoft.JSON package (listed as Json.NET 6.0.3) is installed.
  4. Add both SOD_CS_Library and SocketIOClient to your project references.
    • Right-click your project file, choose Add...Reference.
    • On the left menu, choose Solution, and you should see the SOD library and socketIOclient projects you added in step 1. Select both of them.
  5. Check to see that SOD_CS_Library references include:
    • Newtonsoft.Json
    • SocketIOClient (if this is missing, do the same as step 3 to add it)

Your project should build at this point.

Using SoD in your project:

Prepare an instance of SoD:

  1. Add namespace to your application
    • using SOD_CS_Library;
  2. Create an instance of SoD:
    • SOD_CS_Library.SOD SOD;
  3. Connect to server when your app is ready (server must be running):
    • SOD = new SOD_CS_Library.SOD(address, port);
    • address is a string of format "", port is an int (most likely 3000)

Subscribing to events:

Note: Event handlers should be set up before connecting to the server.

  1. Having prepared an instance of SOD, you can handle events with:

SOD.socket.On("eventNameToListenTo", (messageReceived) =>
//Parse received message
Dictionary<string, dynamic> parsedMessage = SOD.ParseMessageIntoDictionary(messageReceived);

//You can access the parsed information like this:
string eventName = parsedMessage["name"]; //name of event
object data = parsedMessage["data"]; //data sent by other device
int PID = parsedMessage["PID"];  //message ID, used for replying

//To send a reply/acknowledgement:
Dictionary<string, string> dictionaryToSendBack; //make some sample object to send back
SOD.SendAcknowledgementWithPID(parsedMessage["PID"], dictionaryToSendBack);

Set up your own device:

SOD requires information about your device, such as the width and height.
The main properties can be set with:

  • SOD.ownDevice.SetDeviceInformation(widthInMM, heightInMM, locationX, locationY, locationZ, deviceType, stationary);

Additional properties can be set individually:

  • SOD.ownDevice.ID not used by server, but can help user identify device
  • SOD.ownDevice.locationX X coordinate of location, set for stationary devices
  • SOD.ownDevice.locationY Y coordinate of location, set for stationary devices
  • SOD.ownDevice.locationZ Z coordinate of location, set for stationary devices
  • SOD.ownDevice.deviceType what device it is, eg. "iPad" or "table"
  • SOD.ownDevice.orientation no need to set this, might be useful for stationary devices though
  • SOD.ownDevice.height device height in mm, used to calculate devices in view and intersection points
  • SOD.ownDevice.width device width in mm, used to calculate devices in view and intersection points
  • SOD.ownDevice.FOV how wide is the field of view of the device, to calculate devices in view
  • SOD.ownDevice.ownerID usually should not be set by user, used by server to identify someone who is paired with the device
  • SOD.ownDevice.pairingState pairing state, server will use this during pairing
  • SOD.ownDevice.deviceIP IP address of the device, will be set by server upon connection

Connecting to server:

When the address and port are provided, the event handlers are setup, and the device information is set as well, SOD can connect to the server with:

  • SOD.SocketConnect();

Sending a request to server

There are four main types of requests sent to the server:

  1. Send information to server: These requests tell the server about the device.
    • SendOrientation (angle the device is facing - use calibrateDeviceAngle to set current angle to 0)
    • TryPairWithID (device wants to pair with a person)
    • UnpairDevice (device wants to unpair)
  2. Get information from server: These requests get information stored on the server.
    • GetDevicesWithSelection (get a list of all devices in the selection, eg. "inView","paired" or you can de a chain selection : ["all", "single101", "paired", "nearst"], the first selection in the arry gets filtered first, also "single101" means gets single device with ID=101)
    • GetDeviceByID (get a single device by its ID)
    • GetAllTrackedPeople (get a list of all people tracked by server)
  3. Send information to a device: These requests provide a selection for the server to determine which devices will receive the information ("all", "inView", etc.)
    • SendStringToDevices (send a string to specified device or devices)
    • SendDictionaryToDevices (send a dictionary to specified device or devices)
  4. Request information from a device
    • RequestDataFromSelection (ask for some data with "requestName", from all devices in selection, eg. "all", inView", etc.)