... | ... | @@ -4,10 +4,10 @@ In this tutorial we will describe how to develop a simple message exchange betwe |
|
|
Furthermore, we will introduce the observe mechanism.
|
|
|
|
|
|
## 0. The requirements for this tutorial:
|
|
|
• JAVA SE JDK 1.6+
|
|
|
• Eclipse IDE for JAVA development
|
|
|
• Prepared JAVA project files for Hands-on
|
|
|
• (Copper plugin for Mozilla Firefox)
|
|
|
* JAVA SE JDK 1.6+
|
|
|
* Eclipse IDE for JAVA development
|
|
|
* Prepared JAVA project files for Hands-on
|
|
|
* (Copper plugin for Mozilla Firefox)
|
|
|
|
|
|
The following points will be covered by this tutorial:
|
|
|
1. Installation of Copper Plugin for Mozilla Firefox
|
... | ... | @@ -27,66 +27,63 @@ The following points will be covered by this tutorial: |
|
|
-- https://gitlab.amd.e-technik.uni-rostock.de/ws4d/jcoap
|
|
|
|
|
|
• Task 1 – Sequence Diagram:
|
|
|
Server Side Client Side
|
|
|
Communication
|
|
|
Server:
|
|
|
TemperatureResource:
|
|
|
BasicCoapResource:
|
|
|
CoapResource (interface):
|
|
|
CoapResourceServer:
|
|
|
CoapServer (interface):
|
|
|
ChannelManager:
|
|
|
Channel:
|
|
|
Client:
|
|
|
CoapClient (interface):
|
|
|
individual implementation of a server application, creates CoapResourceServer and resources
|
|
|
individual resource, inherits from BasicCoapResource
|
|
|
already implemented resource with basic functionality, implements CoapResource (interface)
|
|
|
describes interfaces that must be supported by each resource
|
|
|
manages a list of resources, enables access of these resources from outside, implements
|
|
|
CoapServer (interface), uses ChannelManager for connection management
|
|
|
describes interfaces that must be supported by a resource server
|
|
|
manages channels
|
|
|
one channel represents a connection to one client
|
|
|
individual implementation of a client application, implements CoapClient (interface)
|
|
|
describes interfaces that must be supported by a client
|
|
|
|
|
|
|
|
|
• ToDo on server side:
|
|
|
• ToDo on client side:
|
|
|
|
|
|
|
|
|
## 3. Import of prepared project into Eclipse
|
|
|
1. File > Import
|
|
|
2. General > Existing Projects ...
|
|
|
3. Click ‚Next‘
|
|
|
4. Browse <Select Project Folder>
|
|
|
5. Click ‚Finish’
|
|
|
|
|
|
Server Side
|
|
|
|
|
|
Client Side
|
|
|
|
|
|
- Server:individual implementation of a server application, creates CoapResourceServer and resources
|
|
|
- TemperatureResource:individual resource, inherits from BasicCoapResource
|
|
|
- BasicCoapResource:already implemented resource with basic functionality, implements CoapResource (interface)
|
|
|
- CoapResource (interface):describes interfaces that must be supported by each resource.
|
|
|
- CoapResourceServer:manages a list of resources, enables access of these resources from outside, implements
|
|
|
- CoapServer (interface), uses ChannelManager for connection management.
|
|
|
- CoapServer (interface):describes interfaces that must be supported by a resource server
|
|
|
- ChannelManager:manages channels
|
|
|
- Channel:one channel represents a connection to one client
|
|
|
- Client:individual implementation of a client application, implements CoapClient (interface)
|
|
|
-CoapClient (interface):describes interfaces that must be supported by a client
|
|
|
|
|
|
* ToDo on server side:
|
|
|
1. Create a new resource class TemperatureResource
|
|
|
2. Instantiate a new ResourceServer
|
|
|
3. Instantiate a new TemperatureResource
|
|
|
4. Add the TemperatureResource to the ResourceServer
|
|
|
5. Run the ResourceServer
|
|
|
|
|
|
* ToDo on client side:
|
|
|
1. Establish a connection to the Server using the ChannelManager
|
|
|
2. Create a CoapRequest & add some Options
|
|
|
3. Send the CoapRequest
|
|
|
4. Wait for CoapResponse
|
|
|
5. Print the CoapResponse on the console
|
|
|
|
|
|
• the resulting GUI should look like this:
|
|
|
• We have prepared some FIXME and TODO annotations:
|
|
|
o Just open the „Task“ view
|
|
|
o FIXMEs are for the first task (message exchange)
|
|
|
o TODOs are for the second task (observe and AC control)
|
|
|
• If you do not have a „Task“ view:
|
|
|
o Window > Show View > Other
|
|
|
o Type „task“
|
|
|
o Select „General > Task“ view
|
|
|
|
|
|
## 3. Import of prepared project into Eclipse
|
|
|
1. File > Import
|
|
|
2. General > Existing Projects ...
|
|
|
3. Click ‚Next‘
|
|
|
4. Browse <Select Project Folder>
|
|
|
5. Click ‚Finish’
|
|
|
|
|
|
* the resulting GUI should look like this:
|
|
|
|
|
|
* We have prepared some FIXME and TODO annotations:
|
|
|
** Just open the „Task“ view
|
|
|
** FIXMEs are for the first task (message exchange)
|
|
|
** TODOs are for the second task (observe and AC control)
|
|
|
* If you do not have a „Task“ view:
|
|
|
** Window > Show View > Other
|
|
|
** Type „task“
|
|
|
** Select „General > Task“ view
|
|
|
|
|
|
## 4. Task 1: Implementation of client/server and enable simple message exchange
|
|
|
|
|
|
1. Create a new resource class TemperatureResource (already done in our example Server)
|
|
|
2. Instantiate a new ResourceServer
|
|
|
3. Instantiate a new TemperatureResource
|
|
|
4. Add the TemperatureResource to the ResourceServer
|
|
|
5. Run the ResourceServer
|
|
|
|
|
|
1. Create a new resource class TemperatureResource (TemperatureResource.java):
|
|
|
* We could have used the predefined BasicCoapResource
|
|
|
* BasicCoapResource is a resource that just keeps a static `byte[ ]` that is:
|
... | ... | @@ -112,14 +109,9 @@ o Select „General > Task“ view |
|
|
3. Instantiate a new TemperatureResource (Server.java, FIXME 2):
|
|
|
* Resources are created like normal objects and added to the server
|
|
|
`CoapResource resource = new CoapResource();`
|
|
|
1. Create a new resource class TemperatureResource
|
|
|
2. Instantiate a new ResourceServer
|
|
|
3. Instantiate a new TemperatureResource
|
|
|
4. Add the TemperatureResource to the ResourceServer
|
|
|
5. Run the ResourceServer
|
|
|
already done in our example Server
|
|
|
• Use the „Tasks“ view of Eclipse to find the right places
|
|
|
• Solve only FIXME 1-3 as described by the following instructions - ignore other FIXMEs or TODOs
|
|
|
|
|
|
* Use the „Tasks“ view of Eclipse to find the right places
|
|
|
* Solve only FIXME 1-3 as described by the following instructions - ignore other FIXMEs or TODOs
|
|
|
|
|
|
4. Add the TemperatureResource to the ResourceServer (Server.java, FIXME 3):
|
|
|
* Resources are created like normal objects and added to the server
|
... | ... | @@ -133,22 +125,19 @@ already done in our example Server |
|
|
** Create another resource type e.g.: humidity or current Time
|
|
|
*** Tip: make a copy of „TemperatureResource.java“
|
|
|
|
|
|
1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5):
|
|
|
* A client must implement CoapClient interface
|
|
|
public class Client implements CoapClient {
|
|
|
* A CoapChannelManager is used to manage different connections and to establish a connection to a server
|
|
|
`channelManager = BasicCoapChannelManager.getInstance();`
|
|
|
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
|
|
|
Client
|
|
|
* Use the „Tasks“ view of Eclipse to find the right places
|
|
|
* Solve only FIXME 4-9 as described by the following instructions - ignore other FIXMEs or TODOs
|
|
|
1. Establish a connection to the Server using the ChannelManager
|
|
|
2. Create a CoapRequest & add some Options
|
|
|
3. Send the CoapRequest
|
|
|
4. Wait for CoapResponse
|
|
|
5. Print the CoapResponse on the console
|
|
|
already done in our example
|
|
|
5. Print the CoapResponse on the console (already done in our example)
|
|
|
|
|
|
1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5):
|
|
|
* A client must implement CoapClient interface
|
|
|
public class Client implements CoapClient {
|
|
|
* A CoapChannelManager is used to manage different connections and to establish a connection to a server
|
|
|
`channelManager = BasicCoapChannelManager.getInstance();`
|
|
|
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
|
|
|
2. Create a CoapRequest & add some Options (Client.java, FIXME 6-8):
|
|
|
* A channel represents a single connection and is used to create and send requests
|
|
|
`Boolean reliable = false;`
|
... | ... | @@ -162,6 +151,7 @@ already done in our example |
|
|
`public void onConnectionFailed(...)`
|
|
|
`public void onResponse(...) // = Unicast`
|
|
|
`public void onMCResponse(...) // MC = Multicast`
|
|
|
|
|
|
* Run Server: select Server.java and click on Run -> Run in the Menu bar
|
|
|
* Run Client: select Client.java and click on Run -> Run in the Menu bar
|
|
|
* Stretch goal:
|
... | ... | |