shamblett / coap

A Coap package for dart
Other
16 stars 13 forks source link

How can I check that the package is work? #2

Closed micrcx closed 3 years ago

micrcx commented 5 years ago

I've snap the project from repository and compiled it without problem. All tests pass. However, the execution of simple_client.dart fails with the error:

/usr/lib/dart/bin/dart --enable-asserts --enable-vm-service:60640 /home/michael_k/IdeaProjects/coap_dart/examples/simple_client.dart
Observatory listening on http://127.0.0.1:60640/

Resolved address : InternetAddress('::1', IPv6)
SJH - isLinkLocal - false
SJH - isLoopback - true
SJH - isLinkMulticast - false
SJH - type - InternetAddressType: IPv6
Simple client, sending request to localhost with path .well-known/core, waiting for response....
Unhandled exception:
SocketException: Send failed (OS Error: Address family not supported by protocol, errno = 97), address = localhost, port = 5683
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3      _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

Process finished with exit code 255

Not sure that this error has any significant significance, since I don’t understand how a client can be checked if the server (or simple_server) is missing. Do you plan to write simple server? It's interesting to look at the real interaction of two applications.

shamblett commented 5 years ago

The idea is to use the simple server from the OCF Iotivity-Lite project, however I'm a way off this yet, not only do I have to get this working as a COAP client with a normal COAP server such as coap.me for instance I then have to mod it to work with iotivity which has its own slightly different COAP implementation.

At the mo though I'm still trying to get it working reliably on IPV6 loopback, the network stack needs some work, the port from C# didn't work well with Dart, it needs to be reworked I think. This is why the package is still not published on pub. Its been a low priority package(too low!) for me for a while now.

Feel free to work on it if you wish.

micrcx commented 5 years ago

Is it possible to use simple server from iotivity-lite? In principle Iotivity lite simple server can work without the security layer, I've check this. In any case, in iotivity-lite, simple server/client interact with each other if them were built without the security layer. Or will there be any problems with this because of your specific implementation of CoAP?

shamblett commented 5 years ago

Iotivity-Lite simple client/server do interact with each other without security out of the box, I've tried this, first step, I want the coap client to interact with the simple server in the same way. I've not even thought about security yet. I don't have a specific implementation of COAP, its just vanilla COAP, its Iotovity that alters the implementation(or they certainly used to).

micrcx commented 5 years ago

If change one line in the lookupHost method of the CoapUtil class (_coaputil.dart), as shown below:

static Future<InternetAddress> lookupHost(String host) async {
    final Completer<InternetAddress> completer = Completer<InternetAddress>();
    final List<InternetAddress> addresses =
    //    await InternetAddress.lookup(host, type: InternetAddressType.IPv6);
      await InternetAddress.lookup(host, type: InternetAddressType.IPv4);
    logResolvedAddresses(addresses);
    if (addresses != null && addresses.isNotEmpty) {
      completer.complete(addresses[0]);
    } else {
      completer.complete(null);
    }
    return completer.future;
  }

can avoid crash when running simple_client:

/usr/lib/dart/bin/dart --enable-asserts --enable-vm-service:56502 --pause-isolates-on-exit /home/michael_k/IdeaProjects/coap_dart/examples/simple_client.dart
Observatory listening on http://127.0.0.1:56502/

Resolved address : InternetAddress('127.0.0.1', IPv4)
SJH - isLinkLocal - false
SJH - isLoopback - true
SJH - isLinkMulticast - false
SJH - type - InternetAddressType: IPv4
Simple client, sending request to localhost with path .well-known/core, waiting for response....
No response received, closing client

But no more than that. Check the performance of the client is not yet possible. I tried to use ./simpleserver of iotivity-lite, changing ports, but so far I have not achieved any results. Sorry.

Using pure dart to implement iotivity-lite is a great idea. The only pity is that while nothing works. By the way, I think that writing a dart wrapper for the native code of iotivity-lite is no less difficult, therefore your approach is completely justified.

shamblett commented 5 years ago

IIRC Iotivity is intended to use IPV6 transport, I think you need to change the simple server to use IPV4 but I'm not sure. COAP itself is intended to use IPV6, see here, so I want to get the package to use IPV6 first, hence I'm testing this first. The intention is to publish a COAP package for Dart, with a selectable option to use Iotivity(or any other variants), not to publish an Iotivity specific package,

micrcx commented 5 years ago

Ok. I tried to use coap.me to check, but without success. Maybe I do not understand something. There are two lines: 1) Crawl CoAP Server on IP Address [coap.me] on port [5683] and 2) Or maybe crawl CoAP Server on URI [coap: //coap.me: 5683]. Is the port you are using - really 5683, and should ".well-known / core" be specified as an IP address?

shamblett commented 5 years ago

Yes, this is expected, as I said above the package is not yet finished and fully tested