javascript - Passing arguments that are just getting created -


i making nodejs/express listener , have inputs being created connectlistener being made:

app.get('/server/:args', function(req, res) {    res.sendfile(__dirname + '/index.html');    // ...     var args = req.param("args");    var client = net.connect({port : 50505}, connectlistener(args, client)); }); 

then have connectlistener function:

function connectlistener(args, client) {     console.log("connected server.");     console.log(args);     client.write(args);     // ....  } 

however, error arguments undefined:

typeerror: cannot read property 'write' of undefined     @ connectlistener (c:\users\es\workspace_luna\wpthash\server-src\index.js:39:8)     @ c:\users\es\workspace_luna\wpthash\server-src\index.js:33:43     @ layer.handle [as handle_request] (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\layer.js:82:5)     @ next (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\route.js:100:13)     @ route.dispatch (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\route.js:81:3)     @ layer.handle [as handle_request] (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\layer.js:82:5)     @ c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\index.js:235:24     @ param (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\index.js:332:14)     @ param (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\index.js:348:14)     @ function.proto.process_params (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\lib\router\index.js:392:3) error: can't set headers after sent.     @ sendstream.headersalreadysent (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\node_modules\send\index.js:313:13)     @ sendstream.send (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\node_modules\send\index.js:494:17)     @ onstat (c:\users\es\workspace_luna\wpthash\server-src\node_modules\express\node_modules\send\index.js:585:10)     @ fsreqwrap.oncomplete (fs.js:99:15) 

so, how create client variable such can used in below function? reason making function connectlistener instead of inline plan replicate client across more ports handle simultaneous connections don't want re-use code nor use global set of client variables/array (though suppose could...)

looks problem calling connectlistener should setting function called on connect event:

var client = net.connect({port : 50505}, connectlistener);

if want write specific client specific args, can defining response in connectlistener function:

app.get('/server/:args', function (req, res) {     var client, args;      res.sendfile(__dirname + '/index.html');     // ...      function connectlistener () {        console.log("connected server.");        console.log(args);        client.write(args);        // ....     }     args = req.param("args");    client = net.connect({port : 50505}, connectlistener); }); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -