Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Interop with native OIC client and server #31

Closed
as2902b opened this issue Nov 11, 2015 · 2 comments
Closed

Interop with native OIC client and server #31

as2902b opened this issue Nov 11, 2015 · 2 comments
Assignees
Labels

Comments

@as2902b
Copy link

as2902b commented Nov 11, 2015

While trying to test nodejs js/client.get.js and running a simpleserver from resource/examples of iotivity - I get the following error.
resourceCount = resources.length ? resources.length : 0,
^
TypeError: Cannot read property 'length' of undefined
at /iotivity-node/js/client.get.js:40:29
at wrapper as _onTimeout
at Timer.listOnTimeout as ontimeout

I have matched the URI types to /a/light.

Kindly let us know how to test with native client and server.

@gabrielschulhof
Copy link

Holy deep-fried RAM chips, Batman! Building simpleserver nearly melted my laptop! What's in that code?!

Anyway, I was finally able to build and run simpleserver from iotivity-1.0.0, and I ran js/client.get.js after doing

diff --git a/js/client.get.js b/js/client.get.js
index 5c3d494..928ad54 100644
--- a/js/client.get.js
+++ b/js/client.get.js
@@ -2,7 +2,7 @@ var intervalId,
        handleReceptacle = {},

        // This is the same value as server.get.js
-       sampleUri = "/a/iotivity-node-get-sample",
+       sampleUri = "/a/light",
        iotivity = require( "iotivity-node/lowlevel" );

 // Start iotivity and set up the processing loop

and it did not produce the error you describe. So, I was unable to reproduce it. However, I make no efforts in js/client.get.js to check whether the discovery payload has any resources. I assume that it does. If it doesn't and payload.resources is absent, undefined, or null, then the code will produce the error you've seen.

This is only a bug in iotivity-node if you know for sure that the payload given to js/client.get.js did have resources. Otherwise you need to fix simpleserver to actually deliver the resources in the response to the discovery.

Looking at the code in js/client.get.js, I think I will change it to read

            resourceCount = resources ? resources.length : 0,

after all, because that makes more sense. This will fix the error, but it will only result in correct behaviour if the server actually delivers resources as part of the payload. Otherwise the client will simply hang there. You will have feedback though, because it'll print the response to the terminal as formatted JSON, so it will reveal if the client has received no resources in the response.

@as2902b
Copy link
Author

as2902b commented Nov 12, 2015

He Did It :) Thanks Gabriel. Yes, the resources were being added.
In our recent tests, we are able to talk between native OIC server and iotivity-node client.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants