douxian1895 2017-11-12 06:11
浏览 578

限制Golang中的TCP下载速度

I would like to be able to limit bandwidth of tcp connection in my code. This question has some clues, but not exactly what I want. I have tried to hack src code of go standard lib (net/tcp package), using similar approach, but failed. My main idea is to somehow write data from syscall to internal buffer slowly, thus making OS to drop tcp packets.

  • 写回答

1条回答 默认 最新

  • douwang9650 2018-01-27 13:18
    关注

    As said in the comment, the easiest way is to do it at the OS level with wondershaper tool. If you look at 'wondershaper' script, it uses '/sbin/tc' command from the 'iproute2' package. I understand that it is not exactly what you would like to do, but you can go at a lower level by executing 'tc' commands in your source code with os.exec(). Implementing your own "traffic control" algorithm is maybe too much work and not necessary for your goal.

    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用