englercj / node-esl

FreeSWITCH ESL implementation for Node.js; implements the full Event Socket Library specified in: http://wiki.freeswitch.org/wiki/Esl
http://englercj.github.com/node-esl/
MIT License
170 stars 111 forks source link

add support for binding inbound socket to local address #52

Closed davehorton closed 5 years ago

davehorton commented 8 years ago

On a server with multiple IP addresses it can be necessary to be able to specify which interface/address to bind the client socket to.

englercj commented 8 years ago

This covers your use case, but there are other options in the net.createConnection() method and I don't want to add a param everytime there is one someone needs.

What if instead of changing the constructor to add the param we just supported passing in a socket directly as the first param? That way you can configure it however you want and just pass it in.

Something that would be used like:

var net = require('net');
var esl = require('modesl');

var socket = net.connect(/* your options */);
var conn = new esl.Connection(socket, function () { /* connect listener */ });

That ensures that you can configure the socket however you want. Problem then becomes how to distinguish between an Inbound and Outbound socket. Because (socket, listener) is assumed to be an Outbound connection right now!

Maybe a static method like .createInboundFromSocket(socket) or something? Not sure...

englercj commented 5 years ago

Closing this as v2 will support this use case in a couple different ways.