如何测试 iPhone 上的低带宽条件

发布于 2024-09-11 20:34:03 字数 161 浏览 6 评论 0原文

我有一个可以加载大量二进制数据的应用程序。我遇到过这样的情况:在加载某些二进制数据期间,不稳定的 3G 连接可能会间歇性地中断,从而导致问题。

有没有办法使用模拟器或其他方式来测试低带宽/不稳定的连接场景?

我似乎记得 Adob​​e Flash 在其测试套件中有带宽模拟器。

I have an application that does a lot of binary data loading. I've encountered scenarios where an unstable 3G connection may intermittently cut out during the loading of some of this binary data, causing issues.

Is there any way, using the simulator or otherwise, to test for low-bandwidth/unstable connection scenarios?

I seem to recall Adobe Flash having bandwidth simulators in their test suite.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

┼── 2024-09-18 20:34:03

您可以通过使用互联网共享在 Mac 上创建无线网络、使用防火墙规则降级该接口并将 iPhone 连接到该网络来实现此目的。这实际上可以用于调试连接到无线网络的任何设备。

使用这种技术,您可以模拟极其微弱、有损或潜在的网络。

我使用这种技术而不是 Apple 的官方网络链接调节器有几个原因:

  • 限制只能应用于特定的连接设备,而不会影响开发计算机的网络连接。
  • 它可以编写脚本来模拟快速变化或“突发”的网络。
  • 与 iOS 内置的网络链接调节器不同,您可以在应用程序保留在前台时更改设置。

这使用了 ipfw 的 dummeynet 功能。 ipfw 在现代版本的 OS X 中从技术上来说已被弃用,但它仍然可以正常工作。不幸的是,pf(替代品)尚不支持任意数据包延迟。如果有变化,我会更新这个答案。

创建一个糟糕的 Wi-Fi 网络

  1. 如果您还没有插入以太网,请先插入以太网。
  2. 在系统偏好设置的共享窗格中启用互联网共享。选择“共享您的连接:以太网”并选中“Wi-Fi”。
  3. 将您的手机连接到您刚刚创建的网络,并确保您可以浏览网页。
  4. 告诉 Mac OS 的内置防火墙 (ipfw),以确保应用了延迟的数据包(通过 ipfw 术语中的“dummynet”)仍然通过正常规则进行路由。这允许互联网共享继续工作:

    phil@Nebula ~$ sudo sysctl -w net.inet.ip.fw.one_pass=0
    net.inet.ip.fw.one_pass:0 - > 0
    
  5. 配置 iPhone 流量将通过的低质量管道(14Kb/s 吞吐量,1% 数据包丢失):

    phil@Nebula ~$ sudo ipfw 管道 1 配置 bw 14KB/s
    phil@Nebula ~$ sudo ipfw 管道 1 配置 plr 0.01
    

下一步根据您是在 Mountain Lion 还是在

对于 Mountain Lion (10.8) 或更低版本:

将数据包路由到管道中,但仅适用于通过 AirPort 接口的流量:

phil@Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via en1
00010 pipe 1 ip from any to any via en1

重要:如果如果您使用的是没有物理以太网端口的 Air 或新款 MacBook Pro,您的 AirPort 接口可能会被称为 en0。如果是这种情况,请将上面的 en1 替换为 en0

对于 Mavericks (10.9):

检查 ifconfig 的输出并查找由 Internet 共享创建的桥接接口:

bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=63<RXCSUM,TXCSUM,TSO4,TSO6>
    ether xx:xx:xx:xx:xx:xx
    Configuration:
            id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
            maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
            root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
            ipfilter disabled flags 0x2
    member: en4 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 6 priority 0 path cost 0
    nd6 options=1<PERFORMNUD>
    media: <unknown type>
    status: inactive
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=3<RXCSUM,TXCSUM>
    ether xx:xx:xx:xx:xx:xx
    inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
    Configuration:
            id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
            maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
            root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
            ipfilter disabled flags 0x2
    member: en1 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 5 priority 0 path cost 0
    media: autoselect
    status: active

您需要具有 IP 地址的桥接接口;在大多数情况下,它将是bridge100

将数据包路由到管道中,但仅限于通过桥接接口的流量:

phil@Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via bridge100
00010 pipe 1 ip from any to any via bridge100

如果 bridge100 在您的系统上有不同的名称,请更改它。

模拟不断变化的网络

您可以更改上述步骤 5 中的值 14KB/s0.01 来模拟不同类型的网络。您还可以指定 config delay 1000 来引入 1000 毫秒的延迟。有关更多选项,请参阅联机帮助页

添加规则后,您可以继续重新配置管道。例如,要模拟接近蜂窝覆盖范围的边缘,请在应用程序运行和连接时发出此命令(95% 数据包丢失):

    phil@Nebula ~$ sudo ipfw pipe 1 config plr 0.95

重新配置后无需再次运行 sudo ipfw add 10 ... 管道。您可以编写这些更改的脚本来模拟极其动态的网络环境。

清理

您可以发出 sudo ipfw delete 10 以使一切恢复正常,或者只是重新启动。

You can accomplish this by creating a wireless network on your Mac using Internet Sharing, degrading that interface using firewall rules, and connecting your iPhone to that network. This will actually work to debug any device that connects to a wireless network.

Using this technique, you can simulate extremely meager, lossy, or latent networks.

I use this technique instead of Apple's official Network Link Conditioner for a couple reasons:

  • Throttling can be applied only to specific connected devices, rather than affecting your development machine's network connection.
  • It can be scripted to simulate rapidly changing or "bursty" networks.
  • Unlike the Network Link Conditioner built into iOS, you can change the settings while your application remains in the foreground.

This uses ipfw's dummeynet feature. ipfw is technically deprecated in modern versions of OS X, but it still works fine. Unfortunately, pf (the replacement) doesn't yet support arbitrary packet delays. I'll update this answer if something changes.

Creating an awful Wi-Fi network

  1. Plug into Ethernet if you aren't already.
  2. Enable Internet Sharing in the Sharing pane of System Preferences. Choose to "Share your connection from: Ethernet" and check "Wi-Fi".
  3. Get your phone connected to the network you just created and make sure you can browse the web.
  4. Tell Mac OS's built-in firewall (ipfw) to ensure packets that have latency applied (pass through the "dummynet" in ipfw parlance) are still routed through the normal rules. This allows Internet Sharing to continue working:

    phil@Nebula ~$ sudo sysctl -w net.inet.ip.fw.one_pass=0
    net.inet.ip.fw.one_pass: 0 -> 0
    
  5. Configure the low-quality pipe through which your iPhone's traffic will pass (14Kb/s throughput with 1% packet loss):

    phil@Nebula ~$ sudo ipfw pipe 1 config bw 14KB/s
    phil@Nebula ~$ sudo ipfw pipe 1 config plr 0.01
    

The next step varies depending on whether you're on Mountain Lion or below, or Mavericks.

For Mountain Lion (10.8) or below:

Route packets into the pipe, but only for traffic over your AirPort interface:

phil@Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via en1
00010 pipe 1 ip from any to any via en1

Important: If you're using an Air or new MacBook Pro without a physical ethernet port, your AirPort interface will likely be called en0. Replace en1 with en0 above if that's the case.

For Mavericks (10.9):

Check the output of ifconfig and look for the bridge interface created by Internet Sharing:

bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=63<RXCSUM,TXCSUM,TSO4,TSO6>
    ether xx:xx:xx:xx:xx:xx
    Configuration:
            id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
            maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
            root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
            ipfilter disabled flags 0x2
    member: en4 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 6 priority 0 path cost 0
    nd6 options=1<PERFORMNUD>
    media: <unknown type>
    status: inactive
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=3<RXCSUM,TXCSUM>
    ether xx:xx:xx:xx:xx:xx
    inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
    Configuration:
            id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
            maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
            root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
            ipfilter disabled flags 0x2
    member: en1 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 5 priority 0 path cost 0
    media: autoselect
    status: active

You want the bridge interface that has an IP address; in most cases, it will be bridge100.

Route packets into the pipe, but only for traffic over the bridge interface:

phil@Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via bridge100
00010 pipe 1 ip from any to any via bridge100

Change bridge100 if it has a different name on your system.

Simulating a changing network

You can change the values 14KB/s and 0.01 in step 5 above to simulate different types of networks. You can also specify config delay 1000 to introduce a 1000ms delay. See the manpage for more options.

You can continue to reconfigure the pipe after adding the rule for it. For instance, to simulate nearing the edge of cellular coverage, issue this command while your app is running and connected (95% packet loss):

    phil@Nebula ~$ sudo ipfw pipe 1 config plr 0.95

There is no need to run sudo ipfw add 10 … again after reconfiguring the pipe. You can script these changes to simulate an extremely dynamic network environment.

Cleaning up

You can issue sudo ipfw delete 10 to put everything back to normal, or just reboot.

清晨说晚安 2024-09-18 20:34:03

这是我在 OS X 上使用的一个很棒的脚本,用于限制您想要的任何域的连接速度,或者只是将其关闭。我希望我能记得我从哪里得到它以给予认可。

将代码保存到计算机上的文件中,并将其命名为“throttting”。然后要运行,只需在终端中输入以下内容,然后选择以下速度之一:[full|fast|medium|slow|wwdc|off]

"./throttling medium"

如果您将脚本设置为限制 localhost:3000 和 stackoverflow.com,那么从浏览器(或 iPhone 模拟器或其他设备)中的任何一个域加载页面的响应速度和加载文件速度都会变慢。它对于测试 iphone 连接错误来说真的很棒。

http://gist.github.com/499177

Here is a great script I've used on OS X to throttle connection speed, or just turn it off, for any domain you want. I wish I could remember where I got it from to give credit.

Save the code to a file on your machine and name it "throttling". Then to run, just enter the below in terminal, and select from one of these speeds: [full|fast|medium|slow|wwdc|off].

"./throttling medium"

If you have the script set up to throttle localhost:3000 and stackoverflow.com, then loading up a page from either of those domains in your browser (or iphone simulator or whatever) will respond slower and load files slower. It's been really great for testing iphone connectivity bugs.

http://gist.github.com/499177

忘年祭陌 2024-09-18 20:34:03

如果您关闭 3G 并连接到 WiFi,您可以测试很多东西。

  1. 登录您的路由器并对您的 iPhone 的 MAC 地址进行速率限制。 (测试慢速连接)

  2. 下载数据时关闭 wifi 电源

  3. 下载时重新启动 wifi 路由器,以便手机有连接,失去连接,然后再次连接。 (测试不同的场景)

快乐编码!

You could test a number of things if you turn 3G off and connect to wifi.

  1. Log into your router and rate limit the mac address of your iphone. (to test slow connections)

  2. Kill the power to the wifi when in the middle of downloading data

  3. Reboot the wifi router when downloading so the phone has connection, loses it, and gets it again. ( to test different scenarios )

Happy Coding!

迷雾森÷林ヴ 2024-09-18 20:34:03

我读到有人用 USB 线连接 iPhone 并用铝箔包裹手机进行测试,以减少蜂窝信号。您可以关闭 WiFi 和 3G,只使用 Edge,然后用箔片对其进行衰减。听起来很粗糙,但是...

您也可以使用 iPhone 4 并将其握在手中,将两个天线短接在一起;-)

I read of someone testing with their iPhone connected by USB cable and the phone wrapped in aluminum foil to get the cellular signal reduced. You can turn off WiFi and 3G and just have Edge and then attenuate it with foil. Sounds crude but...

You could also use an iPhone 4 and hold in your hand to short the two antennas together ;-)

走过海棠暮 2024-09-18 20:34:03

Chrome 38 在设备模拟设置中包含网络模拟。您可以选择离线、GPRS、EDGE、3G、DSL 和 WiFi。还模拟增加的延迟。

它不如在真实设备上测试那么准确,但设置速度要快得多。

Chrome 38 includes network emulation in the device emulation settings. You can select from Offline, GPRS, EDGE, 3G, DSL and WiFi. Also emulates increased latency.

It's not as accurate as testing on a real device but it's much quicker to set up.

萌︼了一个春 2024-09-18 20:34:03

嗯,低带宽很简单:关闭Wifi,关闭3G。切断连接也很简单:打开 wifi,建立连接,关闭 wifi 接入点。

Well, low bandwidth is simple: turn off Wifi, turn off 3G. Cutting connection is also simple: turn on wifi, get connected, power off your wifi access point.

七堇年 2024-09-18 20:34:03

我想你可以连接到一台 Mac(如果你有的话)设置为 WiFi 基站(ad-hoc 网络)。然后在 Mac 上设置“虚拟网络”带宽限制和/或高丢包过滤器。

这就是我用来模拟速度较慢、延迟较高的 DSL 线路的方法,我正在制作用于 Mac 的设置软件。

I guess you could connect to a Mac (if you had one) setup as a WiFi base station (ad-hoc network). Then on the Mac set up a "dummynet" bandwidth limit and/or high packet loss filter.

That's what I do to simulate the slower higher-latency DSL lines I am making software to setup for Macs.

别忘他 2024-09-18 20:34:03

在 iPhone 上则不能。一种方法是将您的计算机 WIFI 连接共享到您的 iPhone,但使用特殊的应用程序来减慢速度。

这篇博文描述了一些方法:

http://blog.aptivate.org/2010/01/23/make-sure-your-apps-work-in-the-field/

On the iPhone you can't. One way would be to share your computer WIFI connection to your iPhone but to slow it down using a special application.

This blog post describes some approaches for that:

http://blog.aptivate.org/2010/01/23/make-sure-your-apps-work-in-the-field/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文