-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoAPServer.java
More file actions
73 lines (63 loc) · 1.76 KB
/
Copy pathCoAPServer.java
File metadata and controls
73 lines (63 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.californium.core.CoapServer;
public class CoapCommServer {
// static
private static final Logger _Logger = Logger.getLogger(CoapCommServer.class.getName());
// params
private CoapServer _server;
// constructors
public CoapCommServer() {
this((String[]) null);
}
/**
*
* @param resourceNames
*/
public CoapCommServer(String... resourceNames) {
super();
_server = new CoapServer();
if (resourceNames != null) {
for (String resourceName : resourceNames) {
CoapToMqttResourceHandler cmrh = new CoapToMqttResourceHandler(resourceName);// instantiate new
// CoapToMqttResourceHandler
// object with arguments
// as resourcename
_server.add(cmrh);
_Logger.info("Adding server resource handler: " + cmrh.getURI());
}
}
}
// public methods
/*
* (non-Javadoc)
*
* @see com.labbenchstudios.iot.comm.ICommServer#start()
*/
public boolean start() { // method to start server
boolean success = false;
System.out.println("Server started");
try {
_server.start(); // Coap server is started
} catch (Exception e) {
_Logger.log(Level.SEVERE, "Failed to start CoAP server.", e);
}
return success;
}
/*
* (non-Javadoc)
*
* @see com.labbenchstudios.iot.comm.ICommServer#stop()
*/
public boolean stop() { // public method to stop the COAP server
boolean success = false;
try {
System.out.println("server stopped");
_server.stop(); // Coap server is stopped
} catch (Exception e) {
_Logger.log(Level.SEVERE, "Failed to stop CoAP server.", e);
}
return success;
}
}