Developing Your First Client Application
The steps below provide a general summary of the steps to create a client application and links to the details available in this document. For complete information about the interfaces, classes, and methods of the Java SDK, refer to the Javadoc provided in the SDK bundle.
1. Create a class that extends the VirtualThing class. It is possible to create multiple VirtualThing classes and use many at a time. An instance of the VirtualThing class is a representation of a Thing in the Java SDK that has properties, services, and events. It is the building block for interacting with the ThingWorx Platform. For more details, refer to the Javadoc and to the following topics:
2. Create an instance of the ClientConfigurator class. The ClientConfigurator class provides the parameters required to communicate with the ThingWorx Platform over WebSockets.
3. Add properties, services, and events to the extended VirtualThing class above. Use one of the following ways to add them:
◦ Use annotations. It is preferable to use annotations for well-known properties, services, and events that do not change.
◦ Using Methods to Change Property Values. It is preferable to use methods for areas where annotation/attribute is not supported or for properties, services, and events that do change frequently.
For more information, refer to the following topics:
Refer to:
5. Optionally set the ReconnectInterval and Name properties of the ClientConfigurator instance created in Step 3. Refer to the Javadoc for details on these properties.
6. Create an instance of the
ConnectedThingClient class, passing in the instance of the
ClientConfigurator created above. The
ConnectedThingClient facilitates communication to the ThingWorx Platform, as well as manages any contained
VirtualThing. For a simple example, refer to the topic,
Connecting an Application to the ThingWorx Platform. For more information about the
ConnectedThingClient, refer to the topic,
ConnectedThingClient Component and the Javadoc for this SDK.
7. Create an instance of the extended
VirtualThing class created in Step 1. For more information, refer to
VirtualThing Component.
8. To bind the subscribed properties, services, and events with the ThingWorx Platform, execute the
bindThing method of the
ConnectedThingClient, passing in the
VirtualThing instance. For a simple example, refer to
Working with Things. For more details, refer to the topic,
Binding to the ThingWorx Platform, and the Javadoc.
10. To implement the details of your specific project, write your custom code. The client may be long running, in which case some sort of loop to handle processing would be necessary. The client may connect, do something, and then disconnect. It depends on the specific requirements of your solution.
11. Execute the shutdown() method to stop the client from processing.
|
As of v.6.1.0 of the Edge Java SDK, WebSocket compression is enabled by default for ALL WebSocket communications, including file transfers and pushing property values to ThingWorx. For more information refer to Compression.
|