简体   繁体   English

Java InputStream不读取前导十六进制字节

[英]java inputstream not reading leading hex bytes

I've got a Telnet Client defined as: 我有一个Telnet客户端定义为:

    TelnetClient telnet = new TelnetClient();
    telnet.connect(server, port);

I then get the inputstream: 然后,我得到输入流:

    InputStream in = telnet.getInputStream();

and then try to read stuff on it, in a loop: 然后尝试循环读取内容:

    while (true) {
    int TEST = in.read();
    }

everything seems to go fine as I receive the "text" part of the input... but I'm missing the (very important for me!) leading bytes. 当我收到输入的“文本”部分时,一切似乎都正常了……但是我错过了(对我来说非常重要!)前导字节。 Here is a snoop of what I see going on the port: 这是我在端口上看到的情况的一个窥探:

    64: a88f ffff 3034 3131 3032 3030 3030 3030    ¨...041102000000
    80: 3030 322e 3031 3131 2e36 2e34 2020 3135    002.0111.6.4  15
    96: 2e39 2e33 2020 3030 3132 30                .9.3  00120

notice the "ffff": that's the leading part I need (everything before is garbage: part of the TCP communication). 注意“ ffff”:这是我需要的主要部分(之前的一切都是垃圾:TCP通信的一部分)。

However, when printing my "TEST" variable, I only see the "041102...etc". 但是,在打印我的“ TEST”变量时,我只会看到“ 041102 ... etc”。

I've tried using BOMInputStream too, but I can't get it either. 我也尝试过使用BOMInputStream,但是我也无法使用它。

=> would you have any idea on how I can receive those ? =>您对我如何收到这些钱有任何想法吗?

Thanks for your help ! 谢谢你的帮助 !

The input stream provided by a TelnetClient instance is only going to provide the data characters. TelnetClient实例提供的输入流仅将提供数据字符。 Telenet protocol signalling stuff will have been filtered out by the TelnetClient code. 远程网协议信令东西将已被过滤掉TelnetClient代码。

If you want to get hold of the signalling information, options, etcetera, you will need to use other methods in the TelnetClient API. 如果要掌握信令信息,选项等,则需要在TelnetClient API中使用其他方法。 There are a variety of approaches you could possibly try. 您可以尝试多种方法。 For example, you could register an option handler, or a notification handler, or you could register a "spy stream". 例如,您可以注册选项处理程序或通知处理程序,也可以注册“间谍流”。

如果您确实想查看所有数据,则应该只使用Socket而不是TelnetClient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM