## SWDataNetworkClient

This implements an OSC client to a DataNetwork, so that an external SuperCollider client can also be part of the network.

This class is a subclass of SWDataNetwork, so the methods used in that class can be used in this class as well. In some cases methods have an additional argument, which only need to be set, when called internally, so the user interface is the same as when using SWDataNetwork. Access to nodes, slots and their data is just the same as for a local network.

There are some additional methods to send out OSC messages, or for internal use.

### - Methods -

*new( hostip, name, reg )
  Create a new client, connecting to hostip. hostip should be a hostname or string (the NetAddr of it is created in the class). name is the name that the client will have in the network. reg is a flag, whether or not to register rightaway to the host.
makeGui
  Create a GUI for the client.
setHost ( ip, port )
  Set the ip and port of the host. This is the method called upon receiving the datanetwork announce message. This then calls resetHost.
resetHost ( addr )
  Set the ip and port of the host. This will remove and then re-add the OSC responders with the new host NetAddr.
findHost ( ip )
  Try to find the host, based on the given IP (if none is given, the method will use the IP of the previous host). The client will then get the port number from the file in which it is written by the host (access with curl through http).
lostHost ( )
  Posts a message when the DataNetwork host has quit.
tryReconnect
  Try to find the host (with the method findHost), and register again to that host.
autoregister ( )
autoregister_ ( )
  If true, when the host NetAddr is reset with setHost, the client will automatically register to it.
host ( )
  Retrieve the current host.
myaddr ( )
  Retrieve own address.
lasttime ( )
  Last time the client received a ping message.
worryAboutTime ( )
  Method called to check whether the last time a pong was received is not too late. If it has been too long, the client tries to register anew.
registered ( )
  If set, then the client has been registered succesfully
addExpected ( id, label, size, fromnw )
  Add an expected node to the network. This is the same as in SWDataNetwork. However, if called from an OSC message, then fromnw is set to true and the changes are not sent back to the host.
setData ( id, data, fromnw )
  Set data in the network. This is the same as in SWDataNetwork. However, if called from an OSC message, then fromnw is set to true and the changes are not sent back to the host.
add ( key, slot, fromnw )
  Add a label in the spec of the network. This is the same as in SWDataNetwork. However, if called from an OSC message, then fromnw is set to true and the changes are not sent back to the host.
removeNode ( id, fromnw )
  Remove datanode in the network. This is the same as in SWDataNetwork. However, if called from an OSC message, then fromnw is set to true and the changes are not sent back to the host.

#### - Methods to interface with the remote host

register ( )
  Register to the network.
unregister ( )
  Unregister from the network. This method is called automatically when sclang stops (or library is recompiled).

#### - Sending query messages -

queryExpected ( )
  Query which nodes are expected in the network.
queryNodes ( )
  Query which nodes are present in the network.
querySlots ( )
  Query which slots are present in the network.
querySetters ( )
  Query of which nodes the client is a setter.
querySubscriptions ( )
  Query to which nodes and slots the client is subscribed.
queryClients ( )
  Query which clients are in the network.

#### - Subscribing and unsubscribing to nodes -

subscribeAll ( )
  Subscribe to all nodes.
unsubscribeAll ( )
  Unsubscribe from all nodes currently subscribed to.
removeAll ( )
  Remove all nodes this client is a setter of.
subscribeNode ( node )
  Subscribe to a node. node can be an instance of SWDataNode or a node ID.
unsubscribeNode ( node )
  Unsubscribe from a node. node can be an instance of SWDataNode or a node ID.
subscribeSlot ( slot )
  Subscribe to a slot. slot can be an instance of SWDataNode or a slot ID (Array of size 2).
unsubscribeSlot ( slot )
  Unsubscribe from a slot. slot can be an instance of SWDataNode or a slot ID (Array of size 2).
getNode ( node )
  Get data from a node just one single time. node can be an instance of SWDataNode or a node ID.
getSlot ( slot )
  Get data from a slot just one single time. slot can be an instance of SWDataNode or a slot ID (Array of size 2).

#### - Private methods called from OSC messages; these message automatically update the data in the network -

nodeInfo ( msg )
slotInfo ( msg )
nodeData ( msg )
slotData ( msg )

#### - Private methods called from OSC messages; these message automatically post an informative message in the post window -

unsubscribeNodeInfo ( msg )
unsubscribeSlotInfo ( msg )
subscribeNodeInfo ( msg )
subscribeSlotInfo ( msg )
clientInfo ( msg )
setterInfo ( msg )

#### - Private methods -

labelNode ( node )
  private - This method is called when this client labels a node in the network, using the add method. This method sends out an OSC message to the host.
labelSlot ( slot )
  private - This method is called when this client labels a slot in the network, using the add method. This method sends out an OSC message to the host.
sendData ( id, data )
  private - This method is called when this client sets data to the network. This method sends out an OSC message to the host with the data.
sendPong ( )
  private - sends a pong to the host. This method is called in response to receiving a ping message.
registered_ ( )
  private - set the registered flag
addResponders ( )
  private - Add all OSC responders
removeResponders ( )
  private - Remove all OSC responders