我们如何计算所有网络或计算android中的特定网络丢包?
问问题
2150 次
2 回答
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
我的手机已经植根,但这绝对不是必需的。
于 2012-05-10T15:50:07.980 回答
0
对于 TCP,可能有可能在 Linux 级别上获取值,但在 Java/Android 级别上却不行。
对于 UDP,这是不可能的,因为没有包含可用于检测数据包丢失的数据。如果要在 UDP 级别计算数据丢失,则必须实现自己的基于 UDP 的协议,并包括例如数据包计数器。但这将只允许您为自己的协议计算数据包丢失,而不是在一般级别上。
于 2012-05-10T13:52:27.053 回答