-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not get response from LwM2M clients when using CoAP+TCP (java-coap) #1675
Comments
Thx for taking time to reporting that. 🙏 Glad to see that you are testing coap+tcp experimental feature. I will try to look at this but maybe not today 😬 Some remarks waiting I take time to look at this deeper :
a null response with synchronous send API means that the request timeout.
I see you are using synchronous send API in /**
* Listen for client registration events.
* <p>
* Those methods are called by the protocol stage thread pool, this means that execution MUST be done in a short delay,
* if you need to do long time processing use a dedicated thread pool.
*/ Could you try with async send API ? |
Thank you! I will try that sometime later. Instead of doing CoAP over TCP, for now I've decided to try if WebSocket proxy would work, as defined in Section 4 of RFC 8323. |
I'm able to reproduce that but using async way to send request, it works for me, with : lwm2mServer.getRegistrationService().addListener(new RegistrationListener() {
@Override
public void registered(Registration registration, Registration previousReg,
Collection<org.eclipse.leshan.core.observation.Observation> previousObservations) {
LOG.info("new device: {}", registration.getEndpoint());
lwm2mServer.send(registration, new ReadRequest(3, 0, 13), response -> {
if (response.isSuccess()) { // <-- error: response is null when using CoAP over TCP
LOG.info("Device time: {}", ((LwM2mResource) response.getContent()).getValue());
} else {
LOG.info("Failed to read: {} {}", response.getCode(), response.getErrorMessage());
}
}, e -> LOG.error("Unexpected error while reading device time", e));
}
@Override
public void updated(RegistrationUpdate update, Registration updatedReg, Registration previousReg) {
LOG.info("device is still here: {}", updatedReg.getEndpoint());
}
@Override
public void unregistered(Registration registration,
Collection<org.eclipse.leshan.core.observation.Observation> observations, boolean expired,
Registration newReg) {
LOG.info("device left: {}", registration.getEndpoint());
}
}); I get
|
I looked at your problem a bit deeper and try to investigate about the sync way you used. I confirm the NPE is because you don't handle the timeout correctly. Code should looks like : lwm2mServer.getRegistrationService().addListener(new RegistrationListener() {
@Override
public void registered(Registration registration, Registration previousReg,
Collection<org.eclipse.leshan.core.observation.Observation> previousObservations) {
LOG.info("new device: {}", registration.getEndpoint());
try {
ReadResponse response = lwm2mServer.send(registration, new ReadRequest(3, 0, 13), TIMEOUT_IN_MS);
if (response == null) {
LOG.info("Read 'Device Time' timeout");
} else if (response.isSuccess()) { // <-- error: response is null when using CoAP over TCP
LOG.info("Device time: {}", ((LwM2mResource) response.getContent()).getValue());
} else {
LOG.info("Failed to read: {} {}", response.getCode(), response.getErrorMessage());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.error("Interrupted while reading device time", e);
} catch (Exception e) {
LOG.error("Unexpected error while reading device time", e);
}
}
@Override
public void updated(RegistrationUpdate update, Registration updatedReg, Registration previousReg) {
LOG.info("device is still here: {}", updatedReg.getEndpoint());
}
@Override
public void unregistered(Registration registration,
Collection<org.eclipse.leshan.core.observation.Observation> observations, boolean expired,
Registration newReg) {
LOG.info("device left: {}", registration.getEndpoint());
}
}); But even with a cleaner code like ☝️, Sync send will not work because this code is executed in Netty NioEventLoopGroup and it should not contain blocking code. I'm not 100% sure but, my understanding : Anyway, I think the right way to do is to use Async Send API. By the way the /**
* Listen for client registration events.
* <p>
* Those methods are called by the protocol stage thread pool, this means that execution MUST be done in a short delay,
* if you need to do long time processing use a dedicated thread pool.
*/ HTH |
@max-pv please let us know if you move forward on that and also If we should close this issue ? |
Version(s)
2.0.0-M16
Which components
leshan-lwm2m-server
Tested With
Leshan Client Demo, Anjay Demo
What happened
When running a Leshan demo a server with a RegistrationListener from Wiki and using Leshan Client (or another LwM2M client) with CoAP+TCP server address, the server timeouts and throws the error from the "relevant output" section.
It works fine when using plain CoAP provider (just
coap://
scheme)How to reproduce
mvn clean install
java -jar ./leshan-demo-server/target/leshan-demo-server-*-SNAPSHOT-jar-with-dependencies.jar -vvv
java -jar leshan-demo-client/target/leshan-demo-client-*-SNAPSHOT-jar-with-dependencies.jar -u coap+tcp://localhost:5683 -n tcp-device-1
Relevant Output
The text was updated successfully, but these errors were encountered: