SocketPair
A pair of coupled Unix sockets (or Windows pipes).
Similar to stream-pair
, but with sockets with real fds and .setTimeout()
.
Originally a workaround for https://github.com/nodejs/node/issues/12716,
but still has some use relevant cases, particularly when building proxies.
Note: This workaround is necessary in node v6.11.1, but not necessary in node v8.2.1. I would assume it is also not necessary in later versions.
Usage
var socketPair = ; var socket = socketPair;
I named them client
and connection
, but their names really have no meaning.
You can call them a
and b
or other
and one
or red
and blue
. It makes no difference.
API
socketPair.create(cb) // creates or reuses a socket server
socketPair.closeAll() // closes the server and all sockets