How to write a Target TUN Link in Java

Page Content:

  1. What is a TUN Link?
  2. Selecting your Networking Architecture
  3. Implementing for Target bind/unbind to TUN
  4. Setting a Listener to the TUN
  5. Opening a session using a UISocket for communication
  6. Receiving commands/values from Client
  7. Sending updates to the Client
  8. Aborting a Session

1. What is a TUN Link?

The abbreviation TUN stands for 'Target-URC-Network'. The TUN Link manages Network specific functions to Discover/Communicate Devices in the Network. It abstracts the underlying Network specific jargon for a Target/Client implementor. The TUN Link may act as a translator between already existing Networking Architectures (e.g. UPnP, Jini, HAVi) and a URC Architecture

2. Selecting your Networking Architecture

Select your Networking Architecture using which Devices can Discover/Communicate with each other. You can either implement the URC-Architecture directly on an existing Physical Network Layer Architecture(WLAN, LAN, Bluetooth, etc.) or select from several Networking Architectures popular in the Industry: Jini, UPnP, HAVi, etc, which also work on popular Physical Networks Layers. We will consider the example of UPnP Networking Architecture. This tutorial will explain how our TUN will translate UPnP Network specific functionality to URC-architecture specific functionality.

3. Implementing for Target bind/unbind to TUN

We have a sample TargetTunManager, which manages Target's and TUN's. Please see: Target - Binding to and configuring a TUN

When a Target binds to a TUN, then it triggers the method:

ITargetTun.configureForTarget(ITarget target, Map<String, Object> parameterMap)

The TUN implementor can do the necessary things as regards to the Networking Architecture being implemented. For example: in Upnp2sTargetTun, the above method creates a New UPnP Device on the fly using the information from the 'parameterMap'. This Device can be discovered/communicated with, in the UPnP network.

When a Target unbinds from a TUN, then it triggers the method:

ITargetTun.unbindTarget(ITarget target)

The TUN implementor can do the necessary things as regards to the Networking Architecture being implemented. For example: in Upnp2sTargetTun, the above method stops the UPnP Device which was created on the fly.

4. Setting a Listener to the TUN

A Listener has to be set for Listening to the events received from the TUN. Using the following method for setting Listener to Target/Client:

ITargetTun.setListener(ITargetTunListener targetTunListener)

In present UrcSdk, TargetTunManager, is an ITargetTunListener

5. Opening a session using a UISocket for communication

On the Target side, when the openSessionRequest message is received from the Network, then the ITargetTun's following method should be called:

ITargetTun.openSessionRequest(String targetName, String socketName, String clientUdn)

The above method should inturn call:

ITargetTunListener.openSessionRequest(String targetName, String socketName, ITargetTun tun)

The Target receives the request from the Client and either approves or dissaproves, according a new sessionId is returned.

6. Receiving commands/values from Client

On the Target side, when the invokeCommandRequest/setElementStateRequest messages are received from the Network, then the ITargetTun's following method should be called:

ITargetTun.invokeCommandRequest(String sessionId, String elementId)

The above method should inturn call:

ITargetTunListener.setElementStateRequest(String sessionId, String elementId, Object value)

The Target receives the request from the Client and either approves or dissaproves.

7. Sending updates to the Client

When a Target has modified certain values, then it calls:

IUISocketElement.setValue(Object value)

The above inturn calls the following method in the TUN:

ITargetTun.updateElementState(String sessionId, String elementId, IUISocketElement element)

The above method has to be implemented according to the Network Specific function for sending update message to the Client.

For example: the Upnp2sTargetTun invokes the UPnP Action on the Target device using the ControlPoint.

8. Aborting a Session

An 'Abort Session' message is sent from the Target to the Client. The message flows as follows:

ITargetTun.abortSession(String sessionId) through Network, to
IClientTun.abortSession(String sessionId) to
IClientTunListener.abortSession(String sessionId)

The Client further takes care of closing the session properly.


Last updated: Parikshit Thakur, 2006-05-05