我们如何在android中计算所有网络或计算特定的网络丢包?
答案 0 :(得分:1)
为了扩展Robert的答案,UDP是一种数据报尽力而为的传递协议,没有任何会话,有序传递或错误检测的概念。如果你想要错误检测,你可能最终会实现大部分TCP(好吧,至少是序列号,校验和和确认)。
幸运的是,对于TCP,内核会跟踪详细的统计信息。标准的ip
实用程序在这里应该有所帮助。在我的SGS2上,该实用程序已完成,并没有像ifconfig
那样减少。
使用示例:
root@android:/etc # ip -s -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
23692 410 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
23692 410 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
2: gannet0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1000 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 72:e0:e5:0a:dc:d6 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
3: sit0: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN
link/sit 0.0.0.0 brd 0.0.0.0
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 59 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
4: ip6tnl0: <NOARP,UP,LOWER_UP> mtu 1452 qdisc noqueue state UNKNOWN
link/tunnel6 :: brd ::
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 62 62 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
5: rmnet0: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ppp
RX: bytes packets errors dropped overrun mcast
1410177 2037 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
199870 1831 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
6: rmnet1: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ppp
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
7: rmnet2: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ppp
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
我的手机根深蒂固,但绝对不是必需的。
答案 1 :(得分:0)
对于TCP,可能有可能获得Linux级别的值,但不能获得Java / Android级别的值。
对于UDP,这是不可能的,因为没有包含可用于检测数据包丢失的数据。如果要计算UDP级别的数据丢失,则必须实现自己的基于UDP的协议,并包括例如数据包计数器。但这样只允许您计算自己协议的丢包率,而不是一般级别。