久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

你如何在 C 中限制套接字連接的帶寬?

How do you throttle the bandwidth of a socket connection in C?(你如何在 C 中限制套接字連接的帶寬?)
本文介紹了你如何在 C 中限制套接字連接的帶寬?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 BSD 套接字編寫客戶端-服務器應用程序.它需要在后臺運行,不斷地傳輸數(shù)據(jù),但不能從正常使用中占用網(wǎng)絡(luò)接口的帶寬.根據(jù)接口的速度,我需要將此連接限制為某個最大傳輸速率.

I'm writing a client-server app using BSD sockets. It needs to run in the background, continuously transferring data, but cannot hog the bandwidth of the network interface from normal use. Depending on the speed of the interface, I need to throttle this connection to a certain max transfer rate.

以編程方式實現(xiàn)這一目標的最佳方法是什么?

What is the best way to achieve this, programmatically?

推薦答案

每次傳輸后休眠 1 秒的問題是您的網(wǎng)絡(luò)性能會不穩(wěn)定.

The problem with sleeping a constant amount of 1 second after each transfer is that you will have choppy network performance.

讓 BandwidthMaxThreshold 為所需的帶寬閾值.

Let BandwidthMaxThreshold be the desired bandwidth threshold.

令 TransferRate 為連接的當前傳輸速率.

Let TransferRate be the current transfer rate of the connection.

那么……

如果檢測到 TransferRate > BandwidthMaxThreshold,則執(zhí)行 SleepTime = 1 + SleepTime * 1.02(將睡眠時間增加 2%)

If you detect your TransferRate > BandwidthMaxThreshold then you do a SleepTime = 1 + SleepTime * 1.02 (increase sleep time by 2%)

在每次網(wǎng)絡(luò)操作之前??或之后做一個睡眠(睡眠時間)

Before or after each network operation do a Sleep(SleepTime)

如果您檢測到您的 TransferRate 遠低于您的 BandwidthMaxThreshold,您可以減少您的 SleepTime.或者,您可以始終隨時間衰減/減少您的 SleepTime.最終您的 SleepTime 將再次達到 0.

If you detect your TransferRate is a lot lower than your BandwidthMaxThreshold you can decrease your SleepTime. Alternatively you could just decay/decrease your SleepTime over time always. Eventually your SleepTime will reach 0 again.

除了增加 2%,您還可以將 TransferRate - BandwidthMaxThreshold 之間的差值線性增加更多.

Instead of an increase of 2% you could also do an increase by a larger amount linearly of the difference between TransferRate - BandwidthMaxThreshold.

這個解決方案很好,因為如果用戶的網(wǎng)絡(luò)已經(jīng)沒有你想要的那么高,你就不會睡覺.

This solution is good, because you will have no sleeps if the user's network is already not as high as you would like.

這篇關(guān)于你如何在 C 中限制套接字連接的帶寬?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 色综合一区二区三区 | 日韩欧美一区二区三区 | 精品亚洲一区二区三区 | 亚洲国产偷 | 一级毛片免费 | 欧美三级三级三级爽爽爽 | 国产精品色综合 | 草草视频在线观看 | 国产精品明星裸体写真集 | 日韩二三区 | 亚洲精品一区中文字幕乱码 | 在线一区视频 | 亚洲综合婷婷 | 国产丝袜人妖cd露出 | 精品一区二区三 | 四色永久 | cao在线 | 北条麻妃国产九九九精品小说 | 一区二区视频在线 | 亚欧精品一区 | 91人人在线| 国产日韩一区二区 | 午夜精品一区 | 国产精品3区 | 99精品欧美一区二区蜜桃免费 | 麻豆久久久9性大片 | 欧美激情精品久久久久久 | 亚洲成av人片在线观看 | 久久视频一区 | 国产精品久久久久免费 | 亚洲精品免费观看 | 欧美一级电影免费 | 国产精品91网站 | com.国产| 天天综合国产 | 亚洲午夜视频在线观看 | 国产精品91久久久久久 | 免费成人高清在线视频 | 亚洲黄色av| 一区二区在线 | av影音 |