telnet.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. class Telnet {
  2. /*
  3. Sent Received Meaning
  4. WILL DO Sender want to use a facility, receiver can handle it, option in effect
  5. WILL DONT Sender want to use a facility, receiver can not, option disabled
  6. DO WILL Sender is handling a facility, receiver will send, option in effect
  7. DO WONT Sender is handling a facility, receiver can not, option disabled
  8. WONT DONT Option Disabled, only valid response
  9. DONT WONT Option Disabled, only valid response
  10. */
  11. };
  12. Telnet.IAC = 0xFF;
  13. Telnet.DONT = 0xFE;
  14. Telnet.DO = 0xFD;
  15. Telnet.WONT = 0xFC;
  16. Telnet.WILL = 0xFB;
  17. Telnet.StartSubNegotiation = 0xFA;
  18. Telnet.GoAhead = 0xF9;
  19. Telnet.EraseLine = 0xF8;
  20. Telnet.EraseCharacter = 0xF7;
  21. Telnet.AreYouThere = 0xF6;
  22. Telnet.AbortOutput = 0xF5;
  23. Telnet.Interrupt = 0xF4;
  24. Telnet.Break = 0xF3;
  25. Telnet.Mark = 0xF2;
  26. Telnet.NOP = 0xF1;
  27. Telnet.EndSubNegotiation = 0xF0;
  28. Telnet.Echo = 0x01;
  29. Telnet.SuppressGoAhead = 0x03;
  30. Telnet.Status = 0x05;
  31. Telnet.TimingMark = 0x06;
  32. Telnet.TerminalType = 0x18;
  33. Telnet.WindowSize = 0x1F;
  34. Telnet.TerminalSpeed = 0x20;
  35. Telnet.RemoteFlowControl = 0x21;
  36. Telnet.LineMode = 0x22;
  37. Telnet.EnvironmentVars = 0x24;
  38. Telnet.RequestTurnOffEcho = [Telnet.IAC, Telnet.WONT, Telnet.Echo];
  39. Telnet.RequestTurnOnEcho = [Telnet.IAC, Telnet.WILL, Telnet.Echo];
  40. Telnet.sendBinary = function(socket, data) {
  41. var length = data.length;
  42. var buffer = new ArrayBuffer( length * 2 );
  43. var view = new Uint16Array(buffer);
  44. for ( var i = 0; i < length; i++) {
  45. view[i] = data[i];
  46. }
  47. socket.write(Buffer.from(view));
  48. };
  49. Telnet.sendString = function(socket, message) {
  50. socket.write(message);
  51. };
  52. Telnet.negotiate = function(data) {
  53. if(data[0] == Telnet.IAC) {
  54. //TODO: actually listen to the client and negotiate
  55. }
  56. }
  57. module.exports = Telnet;