In your project root path, add a device.properties
file, fill with your device information(configure in aliyun)
productKey =
deviceName =
deviceSecret =
accessKey =
accessSecret =
GetDevice getDevice = new GetDevice("device.properties");
new a access object to listener objec with aliyun access key and secret.
Access access = new Access(getDevice.getAccessKey(),getDevice.getAccessSecret());
Listener listener = new Listener(getDevice.getProductKey(), getDevice.getDeviceName(), getDevice.getDeviceSecret(), new DealServer() {
@Override
public String deal_send_back(String msg) {
if ("hello".equals(msg))
{
return "yes";
}
return null;
}
});
listener.start();
Sender sender = new Sender();
sender.send(listener, access,"hello", new DealClient() {
@Override
public void deal_send_back(String send_back) {
if ("yes".equals(send_back))
{
System.out.println("done! I got " + send_back);
}
}
});
If everything goes normally, your will see done! I got yes
in System.out console.
Full code can be viewed here