node-osc icon indicating copy to clipboard operation
node-osc copied to clipboard

bind error

Open PLG opened this issue 12 years ago • 0 comments

I got the following error.

      throw new Error('implicit bind failed');
      ^
Error: implicit bind failed
    at Socket._startReceiving (dgram.js:321:13)
    at Socket.send (dgram.js:177:8)
    at Object.Client.send (/Users/knev/Project-IoMOOT/trunk/nodejs/node_modules/node-osc/lib/osc.js:84:28)
    at Socket.<anonymous> (/Users/knev/Project-IoMOOT/trunk/nodejs/osc+proxy.js:187:12)
    at Socket.EventEmitter.emit (events.js:88:17)
    at TCP.onread (net.js:390:31)

As it turns out , the _sock member variable becomes null at some point. this._sock.send(buf, 0, buf.length, this.port, this.host);

From http://nodejs.org/api/dgram.html#dgram_dgram_createsocket_type_callback I got this var client = dgram.createSocket("udp4"); client.send(message, 0, message.length, 41234, "localhost", function(err, bytes) { client.close(); });

This is the resulting code ...

// OSC Client
////////////////////

var Client = function (host, port) {
    this.host = host;
    this.port = port;
    //this._sock = dgram.createSocket('udp4');
}

Client.prototype = {
    send: function (message) {
        switch (typeof message) {
            case 'object':
                var buf = min.toBuffer(message);
                var client = dgram.createSocket("udp4");
                client.send(buf, 0, buf.length, this.port, this.host, function(err, bytes) {
                    client.close();
                });
                break;
            case 'string':
                mes = new Message(arguments[0]);
                for (var i = 1; i < arguments.length; i++) {
                    mes.append(arguments[i]);
                }
                var buf = min.toBuffer(mes);
                    //console.log("[ERR]"+this._sock);
                var client = dgram.createSocket("udp4");
                client.send(buf, 0, buf.length, this.port, this.host, function(err, bytes) {
                    client.close();
                });
                break;
            default:
                throw new Error("That Message Just Doesn't Seem Right");
        }
    }                                                  
}

exports.Client = Client;

seems to work...

PLG avatar Dec 11 '12 14:12 PLG