Testing iPhone app with limited network access
Asked Answered
H

4

7

Is there any way of simulating limited or no 3G / Wifi / EDGE connectivity when using the iPhone simulator?

Hibbard answered 5/6, 2009 at 11:5 Comment(0)
C
11

Is it the variations in speed you wish to test? Or access to each technology?

If it's speed then you could use the following ipfw trick, courtesty of Craig Hockenberry of the Icon Factory, to use ipfw to limit connectivity to a given domain. In this example, it's twitter and it limits the speed of all connections to and from the host.

It's a bash script, if you're doing iPhone dev you'll be on a mac so just create it and run in the terminal.

#!/bin/bash

# configuration
host="twitter.com"

# usage
if [ "$*" == "" ]; then
    echo "usage: $0 [off|fast|medium|slow]"
    exit
fi

# remove any previous firewall rules
sudo ipfw list 10 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 10 > /dev/null 2>&1
fi
sudo ipfw list 11 > /dev/null 2>&1
if [ $? -eq 0 ]; then
    sudo ipfw delete 11 > /dev/null 2>&1
fi

# process the command line option
if [ "$1" == "off" ]; then
    # add rules to deny any connections to configured host
    sudo ipfw add 10 deny tcp from $host to me
    sudo ipfw add 11 deny tcp from me to $host
else
    # create a pipe with limited bandwidth
    bandwidth="100Kbit"
    if [ "$1" == "fast" ]; then
        bandwidth="300Kbit"
    elif [ "$1" == "slow" ]; then
        bandwidth="10Kbit"
    fi
    sudo ipfw pipe 1 config bw $bandwidth

    # add rules to use bandwidth limited pipe 
    sudo ipfw add 10 pipe 1 tcp from $host to me
    sudo ipfw add 11 pipe 1 tcp from me to $host
fi
Cobber answered 5/6, 2009 at 11:26 Comment(0)
T
4

You might want to take a look at SpeedLimit, a Preference Pane for OS X that allows you to throttle bandwidth and control latency.

Tensive answered 5/6, 2009 at 12:13 Comment(0)
A
1

If you have iPhone tethering, you can turn off your cable modem/ASDL connection, and route your internet through your iPhone. This method works really well if your carrier is AT&T. If you don't have AT&T as your carrier, you'll have to try one of the other methods to simulate a crappy connection.

Another lo-fi solution, is to wrap your home wireless router in tin foil, or put it in a metal box. What you want to simulate generally is a crappy connection - not a slow connection. The firewall rules will slow the connection, but won't lose random packets.

Since your on a Mac, you can use Dummynet. This plugs into ipfw, but can also simulate packet loss. Here's a typical ipfw with the Dummynet module:

ipfw add 400 prob 0.05 deny sr-ip 10.0.0.0/8
Asperges answered 28/8, 2009 at 6:46 Comment(1)
I had to tweak this a bit for SnowLeopard: ipfw add 400 prob 0.05 drop ip from any to $2Javanese
L
0

You can test no network by turning your airport off :-)

For finer control, Neil's ipfw suggestion is the best way.

Learning answered 5/6, 2009 at 12:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.