iac
Node.js interface to Telnet's Interpret As Command
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 => {
sock.write(iac.will.echo)
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 => {
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
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(80, 24)
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 => {
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) => {
console.log(`Remote terminal size is ${width}x${height}`)
})
sock.write(iac.do.naws)
})
.listen(3000)