@elementbound/nlon

1.2.1 • Public • Published

nlon

This package is the reference implementation of the nlon protocol.

Install

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

Usage

For a more detailed explanation, see the nlon documentation

Server

import { createSocketServer } from '@elementbound/nlon-socket'

const nlonServer = createSocketServer({
  host: 'localhost',
  port: 63636
})

nlonServer.handle('greet', (peer, correspondence) => {
  correspondence.finish('Bye!')
})

Peer

import { Message, MessageHeader } from '@elementbound/nlon'
import { createSocketPeer } from '@elementbound/nlon-socket'

async function getGreeting () {
  const nlonPeer = createSocketPeer({
    host: 'localhost',
    port: 63636
  })

  const correspondence = nlonPeer.send(new Message({
    header: new MessageHeader({
      subject: 'greet'
    }),

    body: 'Hello!'
  }))

  const response = await correspondence.next()
  console.log('Received response:', response)

  correspondence.finish()
}

Documentation

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

License

This package is under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @elementbound/nlon

Weekly Downloads

3

Version

1.2.1

License

MIT

Unpacked Size

53.7 kB

Total Files

11

Last publish

Collaborators

  • elementbound