我正在尝试实现基于 Californium 的 CoAP 客户端。我让这个客户观察一个资源:
public static class CoapCl{
double val = 0;
CoapClient client = new CoapClient("coap://localhost/Ultrasonic");
CoapObserveRelation relation = client.observe(new CoapHandler() {
@Override public void onLoad(CoapResponse response)
{
val = Double.parseDouble(response.getResponseText());
}
@Override
public void onError() {
System.out.println("Failed");
}
});
}
我想从另一个类访问值“val”。我该怎么做 ?我试图像这样从 CoapCl 类调用引用并打印出值:
CoapCl client = new CoapCl();
while(true)
{
System.out.println("Testing: " + client.val);
}
这将打印我从 CoAP 客户端获得的所有值,包括已更改和未更改的值。如果我只想获取更改后的值该怎么办?