views:

1011

answers:

4

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

+5  A: 

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
NeilInglis
Does anyone have this working on Snow Leopard?
coob
A: 

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

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

Roger Nolan
+3  A: 

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

jberry
A: 

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
brianegge