Commit 673fa682 authored by Björn Butzin's avatar Björn Butzin
Browse files

jCoAP now tests each multicast address separately. This avoids "all or nothing" problem.

parent 01a88d81
......@@ -82,7 +82,7 @@
<dependency>
<groupId>org.ws4d.jcoap</groupId>
<artifactId>jcoap-core</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
......
......@@ -27,7 +27,7 @@
<dependency>
<groupId>org.ws4d.jcoap</groupId>
<artifactId>jcoap-core</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</dependency>
</dependencies>
<url>https://gitlab.amd.e-technik.uni-rostock.de/ws4d/jcoap</url>
......
package org.ws4d.coap.example.multicastDiscovery;
import java.net.InetAddress;
import org.ws4d.coap.core.CoapClient;
import org.ws4d.coap.core.CoapConstants;
import org.ws4d.coap.core.connection.BasicCoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapChannelManager;
import org.ws4d.coap.core.connection.api.CoapClientChannel;
import org.ws4d.coap.core.enumerations.CoapRequestCode;
import org.ws4d.coap.core.messages.api.CoapRequest;
import org.ws4d.coap.core.messages.api.CoapResponse;
public class MulticastDiscoveryClient implements CoapClient {
private CoapChannelManager channelManager;
private CoapClientChannel clientChannel;
public static void main(String[] args) {
MulticastDiscoveryClient coapClient = new MulticastDiscoveryClient();
System.out.println("=== START Multicast Discovery Client ===");
/* *************************************************************************************************** */
/* Use multicast address */
/* *************************************************************************************************** */
coapClient.start(CoapConstants.COAP_ALL_NODES_IPV4_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
// coapClient.start(CoapConstants.COAP_ALL_NODES_IPV6_LL_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
// coapClient.start(CoapConstants.COAP_ALL_NODES_IPV6_SL_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
}
public void start(String serverAddress, int serverPort) {
this.channelManager = BasicCoapChannelManager.getInstance();
this.clientChannel = null;
try {
this.clientChannel = this.channelManager.connect(this, InetAddress.getByName(serverAddress), serverPort);
if (this.clientChannel == null) {
System.err.println("Connect failed: clientChannel in null!");
System.exit(-1);
}
} catch (Exception e) {
System.err.println(e.getLocalizedMessage());
System.exit(-1);
}
/* *************************************************************************************************** */
/* Create GET request to /.well-known/core resource */
/* *************************************************************************************************** */
// initialize the request
CoapRequest request = this.clientChannel.createRequest(CoapRequestCode.GET, "/.well-known/core", false);
// add a token to match outgoing multicast message and incoming unicast messages
request.setToken("MCToken".getBytes());
// send the request
this.clientChannel.sendMessage(request);
}
/* *************************************************************************************************** */
/* Implement callback methods */
/* *************************************************************************************************** */
@Override
public void onConnectionFailed(CoapClientChannel channel, boolean notReachable, boolean resetByServer) {
System.err.println("Connection Failed");
System.exit(-1);
}
@Override
public void onResponse(CoapClientChannel channel, CoapResponse response) {
if (response.getPayload() != null) {
System.out.println("Response: " + response.toString() + " (" + new String(response.getPayload()) + ")");
} else {
System.out.println("Response: " + response.toString());
}
}
@Override
public void onMCResponse(CoapClientChannel channel, CoapResponse response, InetAddress srcAddress, int srcPort) {
if (response.getPayload() != null) {
System.out.println("Response from "+ srcAddress.toString() + ":" + srcPort + " - " + response.toString() + " (" + new String(response.getPayload()) + ")");
} else {
System.out.println("Response from "+ srcAddress.toString() + ":" + srcPort + " - " + response.toString());
}
}
}
......@@ -23,8 +23,8 @@ public class MulticastDiscoveryClient implements CoapClient {
/* *************************************************************************************************** */
/* Use multicast address */
/* *************************************************************************************************** */
// coapClient.start(CoapConstants.COAP_ALL_NODES_IPV4_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
coapClient.start(CoapConstants.COAP_ALL_NODES_IPV6_LL_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
coapClient.start(CoapConstants.COAP_ALL_NODES_IPV4_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
// coapClient.start(CoapConstants.COAP_ALL_NODES_IPV6_LL_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
// coapClient.start(CoapConstants.COAP_ALL_NODES_IPV6_SL_MC_ADDR, CoapConstants.COAP_DEFAULT_PORT);
}
......
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.ws4d.jcoap</groupId>
<artifactId>jcoap-core</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<name>jCoAP</name>
<licenses>
<license>
......
......@@ -116,10 +116,20 @@ public class BasicCoapSocketHandler implements CoapSocketHandler {
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV6_LL_MC_ADDR));
} catch(Exception e1){
logger.warn("IPv6 link local multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
}
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV6_SL_MC_ADDR));
} catch(Exception e1){
logger.warn("IPv6 site local multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
}
try{
this.dgramSocket.joinGroup(InetAddress.getByName(CoapConstants.COAP_ALL_NODES_IPV4_MC_ADDR));
} catch(Exception e1){
logger.warn("Multicast socket could not be opened. Continuing without Multicast support.");
logger.warn("IPv4 multicast not available. Continuing without.");
logger.debug(e1.getLocalizedMessage());
}
this.workerThread = new WorkerThread();
......
......@@ -132,7 +132,7 @@ public class PlugTest {
* allowed/disallowed
* GET POST PUT DELETE
*
* -> 2*2*2*5 = 40 Tests
* -> 2*2*2*4 = 32 Tests
*/
//RELIABLE GET EXISTING ALLOWED
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment