npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netlinkwrapper

v2.0.2

Published

Synchronous TCP/UDP sockets via NetLink Sockets

Downloads

3,048

Readme

netlinkwrapper

This is a simple node-gyp module wrapper for the C++ library NetLink Sockets. Meaning this is a very simple wrapper for a very simple socket TCP/UDP library. Also, and perhaps most importantly, this is an implementation that only works synchronously, as opposed to Node's asynchronous paradigm.

Purpose

Obviously node's net module is far more suited for TCP/UDP communications than this module. However, the net module can only work asynchronously, as is Node's design. However if you are in the very odd situation where you need synchronous usage of sockets across platforms then this may suit you.

How to use

As with most node modules, use npm or your preferred package manager to install it for you.

npm install netlinkwrapper

node-gyp is a dependency. Ensure your setup can build C++ modules. Follow their documentation for installing the appropriate C++ build tools based on your environment.

Examples

TCP

const { SocketClientTCP, SocketServerTCP } = require('netlinkwrapper');

const port = 33333;
const server = new SocketServerTCP(port);
const client = new SocketClientTCP(port, 'localhost');

const serverSends = 'hello world!';
const serversClient = server.accept();
serversClient.send(serverSends);

const clientReceived = client.receive();

const identical = serverSends === clientReceived.toString(); // should be true

console.log('the two strings are identical?', identical);

client.disconnect();
server.disconnect();

UDP

const { SocketUDP } = require('netlinkwrapper');

const portA = 54321;
const portB = 12345;

const socketA = new SocketUDP(portA, 'localhost');
const socketB = new SocketUDP(portB, 'localhost');

socketA.sendTo('localhost', portB, 'Hello from socketA');
const got = socketB.receiveFrom();

const identical = got.port === portA;
console.log('identical?', identical); // should be: true

// should be: 'got: 'Hello from socketA' from localhost:54321'
console.log(`got: '${got.data.toString()}' from ${got.host}:${got.port}`);

socketA.disconnect();
socketB.disconnect();

Other Notes

Due to the connection-less nature of UDP, the same constructor can be used to make a "client" or "server" esc UDP socket.

After calling disconnect on a socket it is considered "destroyed", and cannot be re-used. In addition, attempting to call any functions off it will result in Errors being thrown.

TypeScript types are included in this package. They are highly encouraged to use. Attempting to do anything outside the scope of the included types will probably result in Errors being thrown.

Docs

Official documentation can be found online at GitHub.

Alternatives

If you are looking for similar functionality, but without the node-gyp dependency I have made a similar (but much slower) module, SyncSocket.