node_pcap icon indicating copy to clipboard operation
node_pcap copied to clipboard

Closing-Reopening session issue

Open Booyaabes opened this issue 10 years ago • 1 comments

The execution of the code below leads to the following error: node: ../deps/uv/src/unix/core.c:706: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.

var pcap = require("pcap");
var pcap_session = pcap.createSession("eth0", "tcp");

console.log("Listening on " + pcap_session.device_name);

function dataCallback(raw_packet) {
    var packet = pcap.decode.packet(raw_packet),
        data = packet.link.ip.tcp.data;

    if (data) {
        console.log(pcap.print.packet(packet));
        console.log(data.toString());
    }
}

pcap_session.on('packet', dataCallback);

setTimeout(function() {
    console.log("close session");
    pcap_session.close();
    setTimeout(function() {
        console.log("open session");
        pcap_session = pcap.createSession("lo", "tcp");
        pcap_session.on('packet', dataCallback);
    }, 10000);
}, 10000);

Environnement: Ubuntu 14.04 and Debian 7.5 Node.js 0.10.25 node_pcap 1.2.0

Booyaabes avatar Jul 16 '14 16:07 Booyaabes

Check out https://github.com/xkjyeah/node_pcap (referenced in issue #18). I had this same issue, and xkjyeah's code resolved it.

platta avatar Aug 18 '14 18:08 platta