简体   繁体   English

如何从Android的套接字的inputStream()获取TCP标头?

[英]How to obtain TCP header from socket's inputStream() in Android?

Android/Java provides socket APIs for receiving data from TCP server, like: Android / Java提供了套接字API,用于从TCP服务器接收数据,例如:

socket.getInputStream().read(payload);

The payload is data stripped off TCP header as well as IP header. 有效负载是从TCP标头和IP标头剥离的数据。 My question is that possible to get the TCP header? 我的问题是有可能获得TCP标头吗? Thanks. 谢谢。

You can't access TCP headers as explained here: Reading and writing TCP header (options) in Java 您不能按此处所述访问TCP标头: 用Java读写TCP标头(选项)

The thing is that without monitoring your network, you won't be able to access that information from the Java API. 事实是,如果不监视网络,则将无法从Java API访问该信息。

What you might want to try is looking at this library if you really need the TCP headers http://jnetpcap.com . 如果您确实需要TCP标头http://jnetpcap.com,则可能要尝试查看此库。

This library is able to read the packets in real time. 该库能够实时读取数据包。 You would just have to match the packet you received with your socket in Java to the correct packet received by the library. 您只需要将使用Java套接字收到的数据包与库接收的正确数据包进行匹配即可。

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

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