coapjs / node-coap

CoAP - Node.js style
MIT License
531 stars 155 forks source link

coap [Malformed Packet] and async calls #35

Closed alan10 closed 9 years ago

alan10 commented 10 years ago

Hi, I'm using cooja simulator to simulate my coap server so i can´t paste here the code of the server, but basically it has a resource /test/hello that has the following information {info:{name: "sensor1", location:"Room"}}. When i make my request i check that in wireshar it gives me a Malformed Packet, but it retrives the data that i want, what am i doing wrong? my client code is:

const coap = require('coap');
var option = {'Content-Format': 'application/link-format'};
var obj = {hostname:"aaaa::c30c:0:0:3",
    port:5683,
    pathname:"test/hello",
    method: 'GET',
    //query: 'ASDFGASHDT',
    options: option
    };
const req = coap.request(obj);
req.on('response', function(res) {

    res.pipe(process.stdout);
});
req.end();

and a screenshoot of wireshark capture wireshark

and i want to make this call to a set of ip's and wait for the response to send it all when finished, so i've made this functions:

var coap=require('coap');
var bl=require('bl');

var ips=["aaaa::c30c:0:0:3","aaaa::c30c:0:0:2"];

function async(ip, callback) {
    var option = {accept: 'application/json'};
        var obj = {hostname : ip,
        port:5683,
    method: 'GET',
    confirmable: true,
        pathname:"test/hello",      
    options: [{"Accept": "application/json"}]
    };

    var data="";
    var reqCoap = coap.request(obj);

    reqCoap.on('response',function(res){
       res.pipe(bl(function(err, data) {          
            var json = JSON.parse(data);
            callback(json);            
        }));
       res.on('end', function() {
            console.log("ended");
        }); 
    });
    reqCoap.end();
};

with this code it only returns the code sometimes but most times it doesn't return the data.

Can you please help me with this?

mcollina commented 10 years ago

Are you sure the version of CoAP running on your Contiki installation is the RFC version (draft-18)?

It was merged in at the end of last may: https://github.com/contiki-os/contiki/pull/507.

mcollina commented 10 years ago

Can you reproduce the problem using Firefox Copper, or some other implementation that it easier to work with?

mcollina commented 9 years ago

Closing as not updated.