I\'m having trouble wrapping my head around the pipe
function shown in several Node.js examples for the net module.
var net = require(\'net\');
There are 2 sockets per Server-Client Connection (2 endpoints). Socket binds IP Address:Port Number
. The client gets assigned random port numbers, while the server has dedicated port number. This is the basic explanation of how socket works.
Piping is reserved for redirecting a readable stream to a writable stream.
What socket.pipe(socket)
does?
It redirects all the data from the readable stream (server) to the writable stream (client). We can tweak this by adding event listeners as @hexacyanide has pointed out.