cross-platform-sock

1.0.0 • Public • Published

cross-platform-sock

Create unix sockets on both unix systems and windows

npm install cross-platform-sock

build status Build status

On unix it'll just use a unix socket and on windows it'll return a pipe name.

Usage

const xsock = require('cross-platform-sock')
const net = require('net')
 
const server = net.createServer(function (socket) {
  socket.end('hello unix socket')
})
 
const sock = xsock('./test.sock')
 
xsock.unlink(sock, function () {
  server.listen(sock, function () {
    const socket = net.connect(sock)
 
    socket.on('data', function (data) {
      console.log('data:', data)
    })
  })
})

Running the above should print

data: hello unix socket

On all systems.

API

sock = xsock(name)

Create a cross platform socket name.

xsock.unlink(sock, cb)

Unlink a previous socket. Only needed on unix systems. On windows this is just a noop.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i cross-platform-sock

Weekly Downloads

1,359

Version

1.0.0

License

MIT

Unpacked Size

4.58 kB

Total Files

7

Last publish

Collaborators

  • mafintosh