coapjs / node-coap

CoAP - Node.js style
MIT License
528 stars 154 forks source link

Responce not received until `end` is called #369

Closed alfiedouglas-tewke closed 1 year ago

alfiedouglas-tewke commented 1 year ago

I am trying to send a stream of data using observe, following the observe_client.js and observe_server.js examples.

However, the client's response only triggers once the server calls the end method on the response, and not after write is called.

server:

const CoapServer = createServer({
    reuseAddr: true,
});

CoapServer.on('request', (req: IncomingMessage, res: OutgoingMessage) => {
    // Is this an observe request? If not, just proxy it
    if (req.headers.Observe !== 1) {
       ...
    } else {
       res.write("test");
    }
});

client:

const req = coap.request({
    method: "GET",
    hostname: "localhost",
    pathname: "/observe",
    observe: 1,
    confirmable: 1,
});

req.on('response', (res) => {
    console.log("req.on('response')");
    res.pipe(process.stdout);
});

req.end();
alfiedouglas-tewke commented 1 year ago

Strange, so I am now unable to recreate this bug & perhaps was an issue with my setup. So am going to close the issue.