O
O
Oleg Serykh2014-07-11 07:00:39
Node.js
Oleg Serykh, 2014-07-11 07:00:39

What is the meaning of the example line in the node.js documentation?

Example from documentation:
nodejs.org/api/net.html#net_net_createserver_optio...

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);
});

I absolutely cannot understand the meaning of this line. c.pipe(c);
I know that this is a stream redirection, but what is the point of redirecting the output stream to itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Starkov, 2014-07-11
@seryh

This makes sense if the stream is Duplex, i.e. both Readable and Writeable.
For example tcp socket, then this entry is c.pipe(c); means receive data and send back.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question