bjoern.butzin created page: home authored by Björn Butzin's avatar Björn Butzin
...@@ -15,7 +15,6 @@ The following points will be covered by this tutorial: ...@@ -15,7 +15,6 @@ The following points will be covered by 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)
## 1. Installation of Copper Plugin for Mozilla Firefox ## 1. Installation of Copper Plugin for Mozilla Firefox
- https://addons.mozilla.org/de/firefox/addon/copper-270430/ - https://addons.mozilla.org/de/firefox/addon/copper-270430/
...@@ -63,7 +62,6 @@ Client Side ...@@ -63,7 +62,6 @@ Client Side
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: * 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
...@@ -98,6 +96,7 @@ Client Side ...@@ -98,6 +96,7 @@ Client Side
5. Run 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:
* returned on GET requests * returned on GET requests
...@@ -116,9 +115,11 @@ Client Side ...@@ -116,9 +115,11 @@ Client Side
* Returns a `byte[ ]` together with its media type * Returns a `byte[ ]` together with its media type
* And the `getResourceType()` method * And the `getResourceType()` method
* Wich returns a description string of the resource * Wich returns a description string of the resource
2. Instantiate a new ResourceServer (Server.java, FIXME 1): 2. Instantiate a new ResourceServer (Server.java, FIXME 1):
* Need a CoapResourceServer to maintain resources * Need a CoapResourceServer to maintain resources
`CoapResourceServer resourceServer = new CoapResourceServer();` `CoapResourceServer resourceServer = new CoapResourceServer();`
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();`
...@@ -129,6 +130,7 @@ Client Side ...@@ -129,6 +130,7 @@ Client Side
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
`resourceServer.createResource(resource);` `resourceServer.createResource(resource);`
5. Run the ResourceServer (Server.java): 5. Run the ResourceServer (Server.java):
`resourceServer.start();` `resourceServer.start();`
* Run Server: Click on Run -> Run in the Menu bar * Run Server: Click on Run -> Run in the Menu bar
...@@ -147,7 +149,7 @@ Client ...@@ -147,7 +149,7 @@ Client
1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5): 1. Establish a connection to the Server using the ChannelManager (Client.java, FIXME 4-5):
* A client must implement CoapClient interface * 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 * A CoapChannelManager is used to manage different connections and to establish a connection to a server
`channelManager = BasicCoapChannelManager.getInstance();` `channelManager = BasicCoapChannelManager.getInstance();`
`clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);` `clientChannel = channelManager.connect(CoapClient client,InetAddress serverIP, int serverPort);`
...@@ -160,7 +162,7 @@ public class Client implements CoapClient { ...@@ -160,7 +162,7 @@ public class Client implements CoapClient {
3. Send the CoapRequest (Client.java, FIXME 6-8): 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 4. Wait for CoapResponse & Print the CoapResponse on the console
A client has some callbacks that are invoked, when the corresponding event occurs * A client has some callbacks that are invoked, when the corresponding event occurs
`public void onConnectionFailed(...)` `public void onConnectionFailed(...)`
`public void onResponse(...) // = Unicast` `public void onResponse(...) // = Unicast`
`public void onMCResponse(...) // MC = Multicast` `public void onMCResponse(...) // MC = Multicast`
... ...
......