ThingWorx Edge Java SDK > Developing Your First Client Application
Developing Your First Client Application
This section lists the general steps that the rest of this chapter covers, with background explanations and example code. All the examples in this chapter are drawn from the examples provided with the Java SDK bundle, in the directory, samples/src/com/thingworx/sdk and its subdirectories, simple and simplething. These subdirectories contain the source files for the Simple Client and Simple Thing Client applications. The examples build on one another to take you through the creation of a client application in two ways:
1. The first series of examples demonstrate key concepts of connectivity. They show how a client application running on a device connects to a ThingWorx platform, without binding. It then shows how to read a property value, write a value to a property, invoke a service, and trigger events.
2. The second series goes into more detail that includes creating a VirtualThing and binding it to a remote thing on the ThingWorx platform. This series shows how to define services and properties for the VirtualThing.
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:
Working with Things
VirtualThing Component
Setting Up the VirtualThing
2. Create an instance of the ClientConfigurator class. The ClientConfigurator class provides the parameters required to communicate with the ThingWorx platform over websockets.
For example code, refer to in Connecting an Application to the ThingWorx Platform the first series of examples. For more details, see ClientConfigurator Component, and also the Javadoc that comes with the SDK.
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.
Directly call methods in code. 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 sections in the first series of examples:
Reading a Property
Writing a Property
Invoking a Service
Firing Events
In the second series in this chapter, refer to:
The State of Things
In the next chapter, refer to:
Defining Properties, which includes details on Aspects of Properties and on Annotations. For examples of annotations for properties and events, refer to the example in the samples directory of the SDK.
Defining Services
Defining Events.
4. Set the Uri for the server, and set up SecurityClaims. The first series of examples, Connecting an Application to the ThingWorx Platform, shows how to set the URI for the server. For details on security claims, refer to Using Security Claims for Authentication.
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 section, ConnectedThingClient Component and to the Javadoc for this SDK.
7. Create an instance of the extended VirtualThing class created in Step 1. For more information, see 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 Binding to the ThingWorx Platform and to the Javadoc.
9. To start message processing and connection monitoring tasks, execute the start method of the ConnectedThingClient. For a simple example, refer to Connecting an Application to the ThingWorx Platform.
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.