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