Changes
Page history
bjoern.butzin created page: home
authored
Sep 08, 2016
by
Björn Butzin
Hide whitespace changes
Inline
Side-by-side
home.markdown
View page @
3b466d0e
...
...
@@ -15,7 +15,6 @@ The following points will be covered by this tutorial:
*
JAVA SE JDK 1.6+
*
Eclipse IDE for JAVA development
*
Prepared JAVA project files for Hands-on
*
(Copper plugin for Mozilla Firefox)
## 1. Installation of Copper Plugin for Mozilla Firefox
-
https://addons.mozilla.org/de/firefox/addon/copper-270430/
...
...
@@ -63,7 +62,6 @@ Client Side
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
...
...
@@ -98,37 +96,41 @@ Client Side
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:
*
returned on GET requests
*
replaced by the payload on PUT requests
*
appended with the payload on POST requests
*
deleted on DELETE requests
*
We do not want a static
`byte[ ]`
*
Instead we want a random number to be returned on a GET
*
PUT, POST and DELETE are not used
*
->So we implemented TemperatureResource wich extends BasicCoapResource with:
*
A constructor
*
To initialize the resource
*
Disallow POST, PUT and DELETE
*
2 get() Methods
*
Get a list of accepted media types [& query parameters]
*
Returns a
`byte[ ]`
together with its media type
*
And the
`getResourceType()`
method
*
Wich returns a description string of the resource
*
We could have used the predefined BasicCoapResource
*
BasicCoapResource is a resource that just keeps a static
`byte[ ]`
that is:
*
returned on GET requests
*
replaced by the payload on PUT requests
*
appended with the payload on POST requests
*
deleted on DELETE requests
*
We do not want a static
`byte[ ]`
*
Instead we want a random number to be returned on a GET
*
PUT, POST and DELETE are not used
*
->So we implemented TemperatureResource wich extends BasicCoapResource with:
*
A constructor
*
To initialize the resource
*
Disallow POST, PUT and DELETE
*
2 get() Methods
*
Get a list of accepted media types [& query parameters]
*
Returns a
`byte[ ]`
together with its media type
*
And the
`getResourceType()`
method
*
Wich returns a description string of the resource
2.
Instantiate a new ResourceServer (Server.java, FIXME 1):
*
Need a CoapResourceServer to maintain resources
`CoapResourceServer resourceServer = new CoapResourceServer();`
*
Need a CoapResourceServer to maintain resources
`CoapResourceServer resourceServer = new CoapResourceServer();`
3.
Instantiate a new TemperatureResource (Server.java, FIXME 2):
*
Resources are created like normal objects and added to the server
`CoapResource resource = new CoapResource();`
*
Resources are created like normal objects and added to the server
`CoapResource resource = new CoapResource();`
*
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
`resourceServer.createResource(resource);`
`resourceServer.createResource(resource);`
5.
Run the ResourceServer (Server.java):
`resourceServer.start();`
*
Run Server: Click on Run -> Run in the Menu bar
...
...
@@ -147,23 +149,23 @@ Client
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 {
`
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);`
`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;`
`CoapRequestCode reqCode = CoapRequestCode.GET;`
`CoapRequest request = clientChannel.createRequest(reliable,reqCode);`
`request.setUriPath("/temperature");`
`Boolean reliable = false;`
`CoapRequestCode reqCode = CoapRequestCode.GET;`
`CoapRequest request = clientChannel.createRequest(reliable,reqCode);`
`request.setUriPath("/temperature");`
3.
Send the CoapRequest (Client.java, FIXME 6-8):
`clientChannel.sendMessage(request);`
`clientChannel.sendMessage(request);`
4.
Wait for CoapResponse & Print the CoapResponse on the console
•
A client has some callbacks that are invoked, when the corresponding event occurs
`public void onConnectionFailed(...)`
`public void onResponse(...) // = Unicast`
`public void onMCResponse(...) // MC = Multicast`
*
A client has some callbacks that are invoked, when the corresponding event occurs
`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
...
...
...
...