New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

socket-pair

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket-pair

Similar to stream-pair, but with sockets with real fds. A workaround for https://github.com/nodejs/node/issues/12716

latest
npmnpm
Version
1.0.4
Version published
Weekly downloads
243
7.52%
Maintainers
1
Weekly downloads
 
Created
Source

SocketPair

NPM version

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 = require('socket-pair');

var socket = socketPair.create(function (err, other) {
  // socket as in `client = new net.Socket(); client.connect(...);`
  // other as in `server.on('connection', function (conn) { ... })`

  socket.write('123');
  other.on('data', function (chunk) {
    console.log(chunk.toString('utf8'));
  });

  socketPair.closeAll();
});

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

Keywords

tls

FAQs

Package last updated on 29 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts