From 4059183b69d48fb7bb1ffc5891ea53efec344e3c Mon Sep 17 00:00:00 2001 From: tigerbot Date: Thu, 27 Apr 2017 18:38:01 -0600 Subject: [PATCH] gave more power to custom createConnection functions --- wsclient.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wsclient.js b/wsclient.js index 6dcafc1..bebcf46 100644 --- a/wsclient.js +++ b/wsclient.js @@ -111,7 +111,7 @@ function run(copts) { } port = portList[servername] || portList['*']; - localclients[cid] = net.createConnection({ + var createOpts = { port: port , host: '127.0.0.1' @@ -120,10 +120,14 @@ function run(copts) { , remoteFamily: opts.family , remoteAddress: opts.address , remotePort: opts.port - }, function () { - //console.log("[=>] first packet from tunneler to '" + cid + "' as '" + opts.service + "'", opts.data.byteLength); - // this will happen before 'data' is triggered - localclients[cid].write(opts.data); + }; + localclients[cid] = net.createConnection(createOpts, function () { + // this will happen before 'data' or 'readable' is triggered + // We use the data from the createOpts object so that the createConnection function has + // the oppurtunity of removing/changing it if it wants/needs to handle it differently. + if (createOpts.data) { + localclients[cid].write(createOpts.data); + } }); console.info("[connect] new client '" + cid + "' for '" + servername + "' (" + clientHandlers.count() + " clients)");