Giter VIP home page Giter VIP logo

node-abstractsocket's Introduction

node-abstractsocket

Because I like my sockets like my Picasso paintings: abstract.

NPM

Abstract what?

Go read this: http://man7.org/linux/man-pages/man7/unix.7.html, I'll wait.

Examples

Server:

// abstract echo server
const abs = require('./lib/abstract_socket');

const server = abs.createServer(function(c) { //'connection' listener
  console.log('client connected');
  c.on('end', function() {
    console.log('client disconnected');
  });
  c.write('hello\r\n');
  c.pipe(c);
});
server.listen('\0foo');

Client:

const abs = require('./lib/abstract_socket');

var client = abs.connect('\0foo', function() { //'connect' listener
    console.log('client connected');
});

client.on('data', function(data) {
    console.log(data.toString());
});

process.stdin.setEncoding('utf8');
process.stdin.on('readable', function() {
    const chunk = process.stdin.read();
    if (chunk !== null)
        client.write(chunk);
});

API

abs.createServer(connectionListener)

Returns a new AbstractSocketServer object. listen can be called on it passing the name of the abstract socket to bind to and listen, it follows the API used for normal Unix domain sockets. NOTE: you must prepend the path with the NULL byte ('\0') to indicate it's an abstract socket.

Emits an error if the socket(2) system call fails.

AbstractSocketServer.listen(name, [callback]

Binds the server to the specified abstract socket name.

Emits an error if the bind(2) system call fails, or the given name is invalid.

This function is asynchronous. When the server has been bound, 'listening' event will be emitted. the last parameter callback will be added as an listener for the 'listening' event.

abs.connect(name, connectListener)

Creates a connection to the given path in the abstract domain. NOTE: you must prepend the path with the NULL byte ('\0') to indicate it's an abstract socket.

Returns a new net.Socket object.

Emits an error if the socket(2) or connect(2) system calls fail, or the given name is invalid.

Tests

Run tests with npm test.

Thanks

I borrowed massive amounts of inspiration/code from node-unix-dgram by @bnoordhuis :-)

@mmalecki taught me how to inherit like a pro. @randunel refactored it heavily in v2.

node-abstractsocket's People

Contributors

acrisci avatar jazzpi avatar jetforme avatar mvduin avatar nornagon avatar randunel avatar saghul avatar sidorares avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-abstractsocket's Issues

Socket.emit error alwasy crash the caller

I found that this line:
setImmediate(() => sock.emit('error', errnoException(err, 'connect')));

always crashes the client, even if it is wrapped inside a try-catch block.
I found that putting another name, e.g.
setImmediate(() => sock.emit('my error', errnoException(err, 'connect')));
everything is fine, i.e. I can catch the error.

Getting lib_uv_open error when trying to use cluster package

Hi!

I am playing around with abstract sockets with our node server, and one issue I'm running into is getting it to work with the cluster library. It appears that when the workers try to connect, I get the following error:

Error: EEXIST: file already exists, uv_pipe_open
  File "net.js", line 1219, col 18, in createServerHandle
  File "net.js", line 1289, col 14, in Server.setupListenHandle [as _listen2]
  File "net.js", line 1357, col 12, in listenInCluster
  File "net.js", line 1417, col 5, in Server.listen
  File "internal/cluster/round_robin_handle.js", line 25, col 17, in new RoundRobinHandle
  File "internal/cluster/master.js", line 303, col 14, in queryServer
  File "internal/cluster/master.js", line 251, col 5, in Worker.onmessage
  File "internal/cluster/utils.js", line 47, col 8, in ChildProcess.onInternalMessage
  File "events.js", line 323, col 22, in ChildProcess.emit
  File "domain.js", line 482, col 12, in ChildProcess.EventEmitter.emit
  File "internal/child_process.js", line 876, col 12, in emit
  File "internal/process/task_queues.js", line 85, col 21, in processTicksAndRejections

I see that you contribute to libuv so maybe this will make sense to you. I am using node version 12.16.1.

The cluster code works when not using the cluster package, and also when using the cluster package with regular unix domain sockets.

module can not compile for nodejs 12.0.0

Hello,

Today I updated my nodejs to version 12.0.0 and updated the node_modules for my repositories.
I can't seem to install this module. I recorded the output and placed it in this Gist
it appears that the V8 api changed somewhat and is causing these problems.

installation error

npm install abstract-socket

> [email protected] install /home/laplace/node-dbus/node_modules/abstract-socket
> node-gyp rebuild

gyp: Undefined variable node_engine_include_dir in binding.gyp while trying to load binding.gyp

node 6.3.1, Ubuntu 16.04

'node-gyp rebuild' fails when attempting to rebuild latex

latex 0.5.0 apparently contains native modules that were compiled for an earlier version of Atom than mine (1.29.0-beta2), but rebuild fails with the following (this is the partial log from atom's internal console output):

/usr/share/atom/resources/app/apm/node_modules/npm/bin/node-gyp-bin/node-gyp: line 5: /usr/share/atom/resources/app/apm/bin/../node_modules/.bin/node-gyp: Permission denied

npm ERR! Linux 4.17.11-gentoo
npm ERR! argv "/usr/share/atom/resources/app/apm/bin/node" "/usr/share/atom/resources/app/apm/node_modules/npm/bin/npm-cli.js" "--globalconfig" "/[$HOME]/.atom/.apm/.apmrc" "--userconfig" "/[$HOME]/.atom/.apmrc" "rebuild" "--runtime=electron" "--target=2.0.5" "--arch=x64"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the abstract-socket package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs abstract-socket
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls abstract-socket
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /[$HOME]/.atom/packages/latex/npm-debug.log

That first line suggests something's wrong with my permissions, but I'm not sure how to debug.

Thanks for the help.

wrong elf class elfclass64

I am building on Ubuntu 64 bit, for Raspberry armv7l architecture.

The package is throwing following error "wrong elf class elfclass64"

any ideas how to fix this?

update nan to 1.8.0

nan 1.7.0 doesn't compile on recent versions of io.js, please update the dependency to 1.8.0

Is this needed for new versions of node?

My tests show the core net library handling paths starting with '\0' just fine since 0.12, so is this module needed any more?
Perhaps a note in the README.md should clarify it is redundand unless you are on 0.10 or older...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.