Valve game company open source GameNetworkingSockets[1], which supports both reliable data transmission and unreliable data transmission. Its data transmission is based on UDP, which implements a TCP-friendly congestion control mechanism and ensures the fairness of bandwidth occupation. Its rate control formula is based on a famous paper [2]. Now, record its bandwidth calculation program here, just in case:
const int64 k_nMillion = 1000000;
int TFRCCalcX( int s, int64 rtt, float p )
{
// TFRC throughput equation
//
// s
// X_Bps = ----------------------------------------------------------
// R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8)*p*(1+32*p^2)))
//
// b is TCP acknowlege packet rate, assumed to be 1 for this implementation
float R = (double)rtt / k_nMillion;
float t_RTO = MAX( 4 * R, 1.0f );
return static_cast< int >( static_cast<float>( s ) /
( R * sqrt( 2 * p / 3 ) + ( t_RTO * ( 3 * sqrt( 3 * p / 8 ) * p * ( 1 + 32 * ( p * p ) ) ) ) ) );
}
[1]GameNetworkingSockets
[2]Padhye J, Firoiu V, Towsley D, et al. Modeling TCP throughput: A simple model and its empirical validation[J]. ACM SIGCOMM Computer Communication Review, 1998, 28(4): 303-314