简体   繁体   中英

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

Android/Java provides socket APIs for receiving data from TCP server, like:

socket.getInputStream().read(payload);

The payload is data stripped off TCP header as well as IP header. My question is that possible to get the TCP header? Thanks.

You can't access TCP headers as explained here: Reading and writing TCP header (options) in Java

The thing is that without monitoring your network, you won't be able to access that information from the Java API.

What you might want to try is looking at this library if you really need the TCP headers 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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