Closed corneliudascalu closed 9 years ago
Corneliu,
I apologize for the delayed response but I think I know what the issue is: when creating the LeshanClientExample you pass in URLs of the format "coap://localhost"
. Looking back at LeshanClientExample (lines 73-74) we create InetSocketAddress(hostname, port) using that information and (as shown in the documentation) only the hostname, localhost
, should be passed there instead. Hopefully that works.
-JF
Thank you very much for the response. I figured that out in the meantime.
Right now, I'm stuck on another error. It seems like the client is not able to send data through the UDP socket. This happens when I run the code on Android or on my local machine. It only works on the local machine if the server is also running locally. I suspect this may be a problem with a firewall or something, even if I tried using the phone's data connection instead of WiFi and still didn't work.
This is the code:
new LeshanClientExample("127.0.0.1", 5686, "leshan.eclipse.org", 5683);
And this is the error log. If you are able to give me any hint, thank you.
02-09 15:37:40.678 15725-15755/com.fortech.lwm2mproto W/UDPConnector﹕ Exception "java.net.SocketException: sendto failed: EINVAL (Invalid argument)" in thread UDP-Sender-/127.0.0.1:5686[0]: running=true
java.net.SocketException: sendto failed: EINVAL (Invalid argument)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:546)
at libcore.io.IoBridge.sendto(IoBridge.java:515)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
at java.net.DatagramSocket.send(DatagramSocket.java:305)
at org.eclipse.californium.elements.UDPConnector$Sender.work(UDPConnector.java:246)
at org.eclipse.californium.elements.UDPConnector$Worker.run(UDPConnector.java:187)
Caused by: android.system.ErrnoException: sendto failed: EINVAL (Invalid argument)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:176)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:278)
at libcore.io.IoBridge.sendto(IoBridge.java:513)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
at java.net.DatagramSocket.send(DatagramSocket.java:305)
at org.eclipse.californium.elements.UDPConnector$Sender.work(UDPConnector.java:246)
at org.eclipse.californium.elements.UDPConnector$Worker.run(UDPConnector.java:187)
02-09 15:37:41.214 15725-15749/com.fortech.lwm2mproto E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.fortech.lwm2mproto, PID: 15725
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: Request Timed Out: coap://localhost/rd?ep=e0d7e954-f44d-47a8-9b49-a9a3a3780d59 (timeout)
at leshan.client.californium.impl.CaliforniumLwM2mClientRequestSender$SyncRequestObserver.waitForResponse(CaliforniumLwM2mClientRequestSender.java:236)
at leshan.client.californium.impl.CaliforniumLwM2mClientRequestSender.send(CaliforniumLwM2mClientRequestSender.java:96)
at leshan.client.californium.LeshanClient.send(LeshanClient.java:116)
at leshan.client.example.LeshanClientExample.<init>(LeshanClientExample.java:103)
at com.fortech.lwm2mproto.MainActivity$1.doInBackground(MainActivity.java:28)
at com.fortech.lwm2mproto.MainActivity$1.doInBackground(MainActivity.java:17)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Corneliu,
I think the issue if you are going to leshan.eclipse.org is that you need set your client-side hostname (parameter 1) to the externally available host the server should connect back to you on instead of 127.0.0.1. Right now it would get the request but then try to send it to it's own localhost which isn't where your device is (I assume :smile: ).
Thanks. Does that mean that any device that is behind a router and doesn't have a static IP address cannot run a client?
By looking at the error it seems like you are not able to access Californium.properties. 5442-5460/com.fortech.lwm2mproto W/NetworkConfig﹕ Error while storing properties to /Californium.properties To resolve this error you would have to create a new CoapServer(NetworkConfig.createStandardWithoutFile()). The important thing to note is that you are not using file to set Californium properties. In next step, pass this newly created CoapServer as parameter to LeshanClient() constructor. I hope this should help. Thanks,Mrinal Sharma
On Monday, February 9, 2015 9:33 AM, Corneliu Dascalu <notifications@github.com> wrote:
Thanks. Does that mean that any device that is behind a router and doesn't have a static IP address cannot run a client?— Reply to this email directly or view it on GitHub.
Hello Cornelie, I have tested this on Android and it works even if device is behind firewall. You would have to replace 127.0.0.1 with your client side IP. Thanks,Mrinal Sharma
On Monday, February 9, 2015 9:11 AM, John <notifications@github.com> wrote:
Corneliu,I think the issue if you are going to leshan.eclipse.org is that you need set your client-side hostname (parameter 1) to the externally available host the server should connect back to you on instead of 127.0.0.1. Right now it would get the request but then try to send it to it's own localhost which isn't where your device is (I assume ).— Reply to this email directly or view it on GitHub.
@corneliudascalu : my layer 4 knowledge is wanting but the fact that we are using UDP can cause routers to be big problems since it isn't like we are creating a nice TCP socket (of course once TCP is added to the protocol... which is something that is currently being worked on by the IETF to add to CoAP as we speak :smiley: ).
@mrinalsharma Thanks a million! It worked, the problem was the local IP of the phone.
I'm getting a RuntimeException about a timeout when running the LeshanClientExample on Android:
This is what I'm doing:
To clarify, this method is thrown when the client sends the
RegisterRequest
.In case it helps, there are some warnings being logged before this exception is thrown:
This part in particular seems important:
It looks like there is no destination for a request.
Am I doing anything wrong, should I do something differently? Thank you.