Socket
Book a DemoInstallSign in
Socket

@elementbound/nlon-socket

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elementbound/nlon-socket

Socket adapter for nlon

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

nlon-socket

Socket adapter for nlon.

Since nlon by itself is not concerned by the actual method of data transfer, adapters can be used to apply the protocol over various media.

This package provides such an adapter for use with Node's sockets.

Install

  • pnpm: pnpm add @elementbound/nlon-socket
  • npm: npm i @elementbound/nlon-socket
  • yarn: yarn add @elementbound/nlon-socket

Usage

The package provides factory methods to either wrap an existing socket or create a new one and add nlon on top of it.

Server

import { createSocketServer, wrapSocketServer } from '@elementbound/nlon-socket'
import net from 'node:net'

// Wrap an existing instance
const netServer = net.createServer(...)
const nlonServer = wrapSocketServer(netServer)
netServer.listen() // This must be called manually when wrapping

// Create a socket and start listening on it
// You can pass options for both the socket and nlon server
const nlonServer = createSocketServer({
  host: 'localhost',
  port: 63636
})

// Access wrapped net.Server instance
nlonServer.server

Peer

import { createSocketPeer, wrapSocketPeer }
import net from 'node:net'

// Wrap an existing instance
const socket = net.createConnection(...)
const nlonPeer = wrapSocketPeer(socket)

// Connect to host and initialize peer
const nlonPeer = createSocketPeer({
  host: 'localhost',
  port: 63636
})

// Access wrapped net.Socket instance
nlonPeer.socket

Documentation

  • API docs
    • Or generate your own with JSDoc: pnpm doc

License

This package is under the MIT License.

Keywords

nlon

FAQs

Package last updated on 01 May 2023

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