Apache Telnet客户端未接收非ASCII字符
我一直在尝试使用org.apache.commons.net.telnet.telnet.telnetclient
,并且我很难接收非accii字符(在我的情况下,polishs chars,例如ą,ę,ę,,还有其他很少的)。问题不在服务器端 - 当我使用默认的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仔细观察。使用Apache Telnet客户端时,数据包根本不包含非ASCII字符,并且在使用默认的Ubuntu Telnet时,它们确实包含它们: apache telnet 默认的ubuntu telnet
我一直想知道apache客户端是否在某种模式下转向服务器上的某种模式仅发送可以在7位编码的字符。我尝试了几种终端类型或次交二进制传输,但没有成功:
int[] msg = {TelnetCommand.DO,TelnetOption.BINARY};
telnetClient.sendSubnegotiation(msg);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定为什么子谈判不起作用,但我找到了解决方法。
尝试将带有选项0(二进制)的SimpleOptionHandler添加到telnetConnection。这将导致此选项从一开始就可以启用。
I'm not sure why sub negotiation does not work but I found a workaround.
Try to add SimpleOptionHandler with option 0 (BINARY) to TelnetConnection. It will cause that this option will be enabled from the start.