1.1.0 • Published 7 years ago

iac v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

iac

Node.js interface to Telnet's Interpret As Command

npm version npm downloads license

Install with npm:

$ npm install --save iac

iac relies on es6 Proxy, therefore you must use Node.js version 6.0.0 or above.

Examples

As the server

const net = require('net')
const iac = require('iac')

net
  .createServer(sock => {
    // IAC WILL ECHO
    sock.write(iac.will.echo)

    // Handler for IAC SB NAWS
    iac.on(sock, iac.sb.naws, (width, height) => {
      console.log(`Remote terminal is ${width}x${height}`)
    })
  })
  .listen(3000)
As the client
const net = require('net')
const iac = require('iac')

net
  .createConnection('localhost', 3000)
  .on('connect', conn => {
    // IAC SB NAWS 0 80 0 24 IAC SE
    //  A window 80 characters wide, 24 characters high
    //  See RFC 1073

    conn.write(iac.sb.naws(80, 24))
  })

API

iac.OPERATION.OPTION will always be a Buffer, where:

OPERATION is one of:

OPTION is one of:

  • binary (Binary Transmission)
  • echo
  • suppress (Suppress Go Ahead)
  • status not fully supported
  • timing (Timing Mark)
  • terminal (Terminal Type)
  • naws (Negotiate About Window Size)
  • speed (Terminal Speed)
  • flow (Remote Flow Control)
  • linemode
  • env (Environment Variables)

Both OPERATION and OPTION are case insensitive. If either are not one of the operations/options listed then it shall return undefined.

e.g.

const iac = require('iac')

// IAC DONT SUPPRESS-GO-AHEAD
iac.dont.suppress

// IAC WILL LINEMODE
iac.will.linemode 

Subnegotiation

To use subnegotiation, call iac.sb.OPTION():

  • Strings are interpolated into ASCII
  • Numbers are passed directly
  • Passing no arguments implies subnegotiation value required (1).

e.g.

const iac = require('iac')

// IAC SB NAWS 0 80 0 24 IAC SE
iac.sb.naws(80, 24)

// IAC SB TERMINAL-TYPE 1 IAC SE
iac.sb.terminal()

On

iac also provides support for assigning handlers for socket data of specific IAC commands on a socket with iac.on(socket, command, handler). command should be something like iac.do.suppress or iac.sb.status.

e.g.

const net = require('net')
const iac = require('iac')

net
  .createServer(sock => {
    // Do not use `sock.setEncoding` at any point if using `iac.on(sock)`

    // Handlers...
    iac
      .on(sock, iac.will.naws, () => console.log(`Remote will NAWS`))
      .on(sock, iac.wont.naws, () => console.log(`Remote wont NAWS`))
      .on(sock, iac.sb.naws, (width, height) => {
        // Note encoding is operation-specific
        console.log(`Remote terminal size is ${width}x${height}`)
      })

    // Ask socket to negotiate window size
    sock.write(iac.do.naws)
  })
  .listen(3000)