cadpnq / telnetlib

A simple Node.js telnet server/client library.
MIT License
18 stars 2 forks source link

No output (data) from client #5

Open eirikb opened 2 years ago

eirikb commented 2 years ago

Hi

Trying to connect to aardwolf.org MUD, and there isn't any output. Example code:

const telnetlib = require("telnetlib");

const c = telnetlib.createConnection(
  {
    host: "aardwolf.org",
    port: 23,
  },
  () => {
    c.on("data", (data) => {
      console.log("data", data.toString());
    });
  }
);

I'm not sure why, it seems related to this: https://github.com/cadpnq/telnetlib/blob/main/src/TelnetSocket/TelnetReader.js#L43
It works with this hack:

const telnetlib = require("telnetlib");

const c = telnetlib.createConnection(
    {
        host: "aardwolf.org",
        port: 23,
    },
    () => {
        c.reader.flushPolicy.endOfChunk = true;
        c.on("data", (data) => {
            console.log("data", data.toString());
        });
    });
eirikb commented 2 years ago

The reason this doesn't work for specifically aardwolf is because they send \n\r, and not \r\n, while the library expect the other way around: https://github.com/cadpnq/telnetlib/blob/main/src/TelnetSocket/TelnetReader.js#L31-L32

Suggested fix: Support both \r\n and \n\r.

Also suggested (better) fix: Don't do either, just pass the chunk of data to consumer, and let them deal with this.
The current implementation will not work for prompts in aardwolf either, since those don't end at all. Prompt are put into the buffer and sent the next time a line ending will arrive.