'Apache Telnet Client does not recevie non-ASCII characters

I've been trying to useorg.apache.commons.net.telnet.TelnetClient and I am having trouble to receive non-ASCII characters (in my case polish chars like ą,ę,ć,ź and few others). The problem is not on server side - when I use default Ubuntu telnet implementation or Putty I have no problem receiving non-ASCII characters. My code looks something like this (simplified a bit for readability):

    TelnetClient telnetClient = new TelnetClient();
    telnetClient.connect("169.254.24.223", 23);

    while (true) {
        int readCharInt = telnetClient.getInputStream().read();
        if (readCharInt != -1) {
            String s = String.valueOf((char) readCharInt);
            System.out.print(s);
        } else {
            System.out.println("EOS");
            break;
        }
    }

I used Wireshark to take a closer look. When using the Apache telnet client, packets do not contain non-ASCII characters at all, and while using default Ubuntu telnet they do contain them: Apache telnet Default ubuntu telnet

I've been wondering if the Apache client turns on some mode for the server to send only characters that can be encoded on 7 bits. I've tried several terminal types or to subnegotiate binary transmission but without success:

int[] msg = {TelnetCommand.DO,TelnetOption.BINARY};
telnetClient.sendSubnegotiation(msg);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source