4

I need to simulate slow/no network for Dart/Flutter's HttpClient and Socket. However, I cannot find any guides on the network.

My naive idea is as follows. We can create class SlowSocket implements Socket, and use the delegate/decorator design pattern. For example, the SlowSocket.add method will be implemented as Future.delayed(...).then(() => realSocket.add()). I wonder whether this is ok? Or is there a simpler/better approach?

Thanks for any suggestions!

ch271828n
  • 15,854
  • 5
  • 53
  • 88

2 Answers2

1

One way would be to setup a virtual machine like the Android Emulator which has this built-in. Otherwise depending on which platform you're doing your development you could use tools that simulate slow/no network (example for Windows).

Chrome also offer this if you open the developer tools (Ctrl-Shift-I).

ajaysinghdav10d
  • 1,771
  • 3
  • 23
  • 33
ManuH68
  • 481
  • 2
  • 6
1

If you are using Android Studio, I've got you covered.

  1. You may have to open AVD manger enter image description here

  2. Click on "Pencil Icon(edit)"

    enter image description here

  3. Go to advanced settings and then set the network type of your choice in speed and latency section:

    enter image description here

Speeds for reference in increasing kbps:

                            UP       DOWN
                      -------- ----------
    gsm   GSM/CSD         14.4       14.4
    hscsd HSCSD           14.4       57.6
    gprs  GPRS            28.8       57.6
    umts  UMTS/3G        384.0      384.0
    edge  EDGE/EGPRS     473.6      473.6
    hsdpa HSDPA         5760.0   13,980.0
    lte   LTE         58,000.0  173,000.0
    evdo  EVDO        75,000.0  280,000.0
    full  No limit           ∞          ∞
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88