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

osmia-telnet-rxjs

v2.1.1

Published

A node.js telnet library that wraps the sockets with RxJS observables

Downloads

7

Readme

telnet-rxjs

A node.js telnet library that wraps the sockets with RxJS observables.

Build Status

SYNPOSIS

Connect to a remote server

import { Telnet } from 'telnet-rxjs';

// const Telnet = require('telnet-rxjs').Telnet;

// const { Telnet } = require('telnet-rxjs');


const client = Telnet.client('www.yahoo.com:80');

let connected = false;

client.filter((event) => event instanceof Telnet.Event.Connected)
  .subscribe((event) => {
    connected = true;
    client.sendln('GET /');
  });

client.data
  .subscribe((data) => {
    if (!connected) {
      return;
    }
    console.log(data);
  });

client.connect();

Start a server

import { Telnet } from 'telnet-rxjs';

// const Telnet = require('telnet-rxjs').Telnet;

// const { Telnet } = require('telnet-rxjs');

const server = Telnet.server(80);

server.filter((event) => event instanceof Telnet.Event.Connected)
  .subscribe((event) => {
    const socket = event.connection.socket;

    if (!socket) {
      console.error('No socket for', event.connection);
      return;
    }

    console.log('Connection received from', socket.remoteAddress);
    event.connection.sendln('Hello!');
    event.connection.disconnect();
  });

server.start().then(() => {
  console.log('Server has been started.');
});

INSTALLATION

npm install telnet-rxjs

Dependencies

RxJS

DESCRIPTION

telnet-rxjs is a simple wrapper around a telnet client or server, using RxJS for handling data received from the server.

Telnet Client

Create a Connection

Connections are created by using the Telnet.client static factory method or createClient function. This method takes two arguments

  • The URI of the host to connect to
  • Optionally, additional options to pass to the network socket

The URI should be in formats similar to protocol:host:port. Host and port are both required. Protocol can be either telnet or telnets, which uses a TLS connection. If the protocol is not specified, it defaults to telnet.

The options can be any option accepted by the net.connect or tls.connect functions of Node.js. For example, to create a TLS connection to a site with a self-signed certificate, this statement can be used:

const client = Telnet.client('telnets:some.example.com:8443', { rejectUnauthorized: false });

The factory method returns a Telnet.Connection object, which is a subclass of Observable<Telnet.Event>.

Listen for Events and Data

As an observable, the telnet connection can be subscribed to in order to receive data from the server. The default subscription publishes Telnet.Event objects.

Client Events

All events have a timestamp field that is a Date object.

Telnet.Event.Connecting Published when the client begins connecting to the server. The event has a connection property for the client.

Telnet.Event.Connected Published after a connection to the server has been established. The event has a connection property for the client.

Telnet.Event.Disconnecting Published when the client begins to disconnect from the server. The event has a connection property for the client.

Telnet.Event.Disconnected Published when the client has closed its connection to the server. The event has a connection property for the client.

Telnet.Event.Data Published when data is received from the server. The event has a data field that is a string.

Telnet.Event.Command Published when a telnet command has been received from the server. The event has a command field that is a string of numbers.

Additional accessors are provided that act as filters for the Data and Command events. The data accessor publishes each string of data. The commands accessor publishes each array of numbers.

Listen for All Events

Events are all subclasses of Telnet.Event.

client.subscribe((event) => {
  console.log('Received event:', event);
});
Listen for Data

The data will be returned as a string.

client.data.subscribe((data) => {
  console.log('Received data:', data);
});

or

client.filter((event) => event instanceof Telnet.Event.Data).subscribe((event) => {
  console.log('Received data:', event.data);
});
Listen for Commands

The commands will be an array of numbers.

client.commands.subscribe((command) => {
  console.log('Received command:', command);
});

or

client.filter((event) => event instanceof Telnet.Event.Command).subscribe((event) => {
  console.log('Received command:', event.command);
});
Listen for Errors
client.subscribe(
  (event) => {
    console.log('Received event:', event);
  },
  (error) => {
    console.error('An error occurred:', error);
  }
);

or

client
  .catch((error) => {
    console.error('An error occurred:', error);
  })
  .subscribe((event) => {
    console.log('Received event:', event);
  });

Connect

The connect method must be called before any connections will be opened. Configuration errors, such as missing port numbers, will cause an exception to be thrown. Other errors will be reported on the error channel of the client observable.

Disconnect

The disconnect method closes the connection to the server.

Telnet Server

Connections are created by using the Telnet.server static factory method or createServer function. This method takes two arguments

  • The URI of the server to create
  • Optionally, additional options to pass to the network socket

The URI should be in formats similar to protocol:host:port. Only the port is required. Protocol can be either telnet or telnets, which uses a TLS connection. If the protocol is not specified, it defaults to telnet. If the host is not specified, it defaults to 0.0.0.0.

The options can be any option accepted by the net.createServer or tls.createServer functions of Node.js.

The factory method returns a Telnet.Server object, which is a subclass of Observable<Telnet.Event>.

Listen for Events

As an observable, the telnet connection can be subscribed to in order to receive data from the server. The default subscription publishes Telnet.Event objects.

Server Events

All events have a timestamp field that is a Date object.

Telnet.Event.Connecting Published when a client begins connecting to the server. The event has a connection property for the client.

Telnet.Event.Connected Published after a connection to the server has been established. The event has a connection property for the client.

Telnet.Event.Disconnecting Published when a client begins to disconnect from the server. The event has a connection property for the client.

Telnet.Event.Disconnected Published when a client has closed its connection to the server. The event has a connection property for the client.

Telnet.Event.Starting Published when the server begins starting up.

Telnet.Event.Started Published after the server has started up.

Telnet.Event.Ending Published when the server begins shutting down.

Telnet.Event.Ended Published after the server has shut down.

Additional accessors are provided that act as filters for the Data and Command events. The data accessor publishes each string of data. The commands accessor publishes each array of numbers.

Start

The start method must be called before the server will listen and any clients can connect. Configuration errors, such as missing port numbers, will cause an exception to be thrown. Other errors will be reported on the error channel of the server observable.

The method returns a promise that resolves to the [net.Server] to [tls.Server] object that underlies the connection, when the listen method's callback is invoked.

Stop

The stop method will shutdown the server. First, it will call the disconnect method on each connection. Then, it will close the server port.

The method returns a promise that resolves when the close method's callback is invoked.

LINKS

Generated API Documentation

NPM Package

Telnet RFC

AUTHOR

Eric Kidder