# telnet-stream Transform streams that emit TELNET negotiations as events ## Motivation Although venerable, the [TELNET](https://en.wikipedia.org/wiki/Telnet) protocol is still in use by some services and expected by some clients. If you need to connect to something that "speaks TELNET", this module offers some simple objects for that purpose. ## Example 0: A Simple Solution If you need to connect to something that speaks TELNET, but you don't care about options or negotiations, then simply use TelnetSocket to decorate a regular socket. It will filter out all the "TELNET stuff" and pass the remaining data on to you. // get references to the required stuff var TelnetSocket, net, socket, tSocket; net = require("net"); ({TelnetSocket} = require("telnet-stream")); // create a Socket connection socket = net.createConnection(3000, "godwars2.org"); // decorate the Socket connection as a TelnetSocket tSocket = new TelnetSocket(socket); // if the socket closes, terminate the program tSocket.on("close", function() { return process.exit(); }); // if we get any data, display it to stdout tSocket.on("data", function(buffer) { return process.stdout.write(buffer.toString("utf8")); }); // if the user types anything, send it to the socket process.stdin.on("data", function(buffer) { return tSocket.write(buffer.toString("utf8")); }); ## Usage Maybe you have more complex needs. Perhaps you need certain options to be turned on or off, or have important information to pull from a subnegotiation. This is pretty easy to do with TelnetSocket. ### TelnetSocket input TelnetSocket is a decorator for a [net.Socket](https://nodejs.org/api/net.html) object. Incoming TELNET commands, options, and negotiations are emitted as events. Non-TELNET data is passed through without changes. #### Event: 'command' When the remote system issues a TELNET command that is not option negotiation, TelnetSocket will emit a 'command' event. var tSocket = new TelnetSocket(socket); tSocket.on('command', function(command) { // Received: IAC - See RFC 854 }); #### Event: 'do' When the remote system wants to request that the local system perform some function or obey some protocol, TelnetSocket will emit a 'do' event: var tSocket = new TelnetSocket(socket); tSocket.on('do', function(option) { // Received: IAC DO