I saw the next example here
var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
console.log('server connected');
c.on('end', function() {
console.log('server disconnected');
});
c.write('hello\r\n');
c.pipe(c);
});
server.listen(8124, function() { //'listening' listener
console.log('server bound');
});
So createServer() has an anonymous function as a parameter. The way I see it this function listens and sends back whatever it receives, which is c.
Am I right so far? And where is c coming from?
Thanks!
The
cvariable is created inside thenet.createServerfunction.cis returned through the callback given as parameter to thecreateServerfunction.Example:
In your case,
cis not a string of course. It was just for the example. It’s another object: a socket.