簡體   English   中英

Apache Telnet 客戶端不接收非 ASCII 字符

[英]Apache Telnet Client does not recevie non-ASCII characters

我一直在嘗試使用org.apache.commons.net.telnet.TelnetClient並且我無法接收非 ASCII 字符(在我的情況下是波蘭字符,如 ą、ę、ć、ź 和其他幾個字符)。 問題不在服務器端——當我使用默認的 Ubuntu telnet 實現或 Putty 時,接收非 ASCII 字符沒有問題。 我的代碼看起來像這樣(為了便於閱讀,做了一點簡化):

    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;
        }
    }

我使用 Wireshark 仔細觀察。 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

我一直想知道 Apache 客戶端是否打開了某種模式以使服務器僅發送可以編碼為 7 位的字符。 我嘗試了幾種終端類型或對二進制傳輸進行子協商但沒有成功:

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

我不確定為什么子協商不起作用,但我找到了解決方法。

嘗試將帶有選項 0 (BINARY) 的 SimpleOptionHandler 添加到 TelnetConnection。 這將導致從一開始就啟用此選項。

TelnetClient tc = new TelnetClient();
// 1st param 0 means BINARY option
SimpleOptionHandler simpleOptionHandler = new SimpleOptionHandler(0, true, false, true, false);
tc.addOptionHandler(ttopt);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM