class Telnet { /* Sent Received Meaning WILL DO Sender want to use a facility, receiver can handle it, option in effect WILL DONT Sender want to use a facility, receiver can not, option disabled DO WILL Sender is handling a facility, receiver will send, option in effect DO WONT Sender is handling a facility, receiver can not, option disabled WONT DONT Option Disabled, only valid response DONT WONT Option Disabled, only valid response */ }; Telnet.IAC = 0xFF; Telnet.DONT = 0xFE; Telnet.DO = 0xFD; Telnet.WONT = 0xFC; Telnet.WILL = 0xFB; Telnet.StartSubNegotiation = 0xFA; Telnet.GoAhead = 0xF9; Telnet.EraseLine = 0xF8; Telnet.EraseCharacter = 0xF7; Telnet.AreYouThere = 0xF6; Telnet.AbortOutput = 0xF5; Telnet.Interrupt = 0xF4; Telnet.Break = 0xF3; Telnet.Mark = 0xF2; Telnet.NOP = 0xF1; Telnet.EndSubNegotiation = 0xF0; Telnet.Echo = 0x01; Telnet.SuppressGoAhead = 0x03; Telnet.Status = 0x05; Telnet.TimingMark = 0x06; Telnet.TerminalType = 0x18; Telnet.WindowSize = 0x1F; Telnet.TerminalSpeed = 0x20; Telnet.RemoteFlowControl = 0x21; Telnet.LineMode = 0x22; Telnet.EnvironmentVars = 0x24; Telnet.RequestTurnOffEcho = [Telnet.IAC, Telnet.WONT, Telnet.Echo]; Telnet.RequestTurnOnEcho = [Telnet.IAC, Telnet.WILL, Telnet.Echo]; Telnet.sendBinary = function(socket, data) { var length = data.length; var buffer = new ArrayBuffer( length * 2 ); var view = new Uint16Array(buffer); for ( var i = 0; i < length; i++) { view[i] = data[i]; } socket.write(Buffer.from(view)); }; Telnet.sendString = function(socket, message) { socket.write(message); }; Telnet.negotiate = function(data) { if(data[0] == Telnet.IAC) { //TODO: actually listen to the client and negotiate } } module.exports = Telnet;