Quic.NET
1.0.0
0x5C2AAD80
Quicnet是下面提到的QUIC協議的.NET實現。該實施與第32版的Quic-Transport草案一致,並且尚未提供以下相關草案的實施:
最小的示例
using System ;
using System . Text ;
using QuicNet ;
using QuicNet . Streams ;
using QuicNet . Connections ;
namespace QuickNet . Tests . ConsoleServer
{
class Program
{
// Fired when a client is connected
static void ClientConnected ( QuicConnection connection )
{
connection . OnStreamOpened += StreamOpened ;
}
// Fired when a new stream has been opened (It does not carry data with it)
static void StreamOpened ( QuicStream stream )
{
stream . OnStreamDataReceived += StreamDataReceived ;
}
// Fired when a stream received full batch of data
static void StreamDataReceived ( QuicStream stream , byte [ ] data )
{
string decoded = Encoding . UTF8 . GetString ( data ) ;
// Send back data to the client on the same stream
stream . Send ( Encoding . UTF8 . GetBytes ( "Ping back from server." ) ) ;
}
static void Main ( string [ ] args )
{
QuicListener listener = new QuicListener ( 11000 ) ;
listener . OnClientConnected += ClientConnected ;
listener . Start ( ) ;
Console . ReadKey ( ) ;
}
}
} using System ;
using System . Text ;
using QuicNet . Connections ;
using QuicNet . Streams ;
namespace QuicNet . Tests . ConsoleClient
{
class Program
{
static void Main ( string [ ] args )
{
QuicClient client = new QuicClient ( ) ;
// Connect to peer (Server)
QuicConnection connection = client . Connect ( "127.0.0.1" , 11000 ) ;
// Create a data stream
QuicStream stream = connection . CreateStream ( QuickNet . Utilities . StreamType . ClientBidirectional ) ;
// Send Data
stream . Send ( Encoding . UTF8 . GetBytes ( "Hello from Client!" ) ) ;
// Wait reponse back from the server (Blocks)
byte [ ] data = stream . Receive ( ) ;
Console . WriteLine ( Encoding . UTF8 . GetString ( data ) ) ;
// Create a new data stream
stream = connection . CreateStream ( QuickNet . Utilities . StreamType . ClientBidirectional ) ;
// Send Data
stream . Send ( Encoding . UTF8 . GetBytes ( "Hello from Client2!" ) ) ;
// Wait reponse back from the server (Blocks)
data = stream . Receive ( ) ;
Console . WriteLine ( Encoding . UTF8 . GetString ( data ) ) ;
Console . ReadKey ( ) ;
}
}
}QUIC是一種標準化的傳輸層協議,符合由Google設計的RFC 9000,旨在加快以連接為導向的Web應用程序的數據傳輸。該應用程序級協議的目的是通過使用多種技術類似於TCP傳輸,同時減少連接握手,並以一種可以在傳輸過程中交織不同的數據實體,從而從TCP轉換為UDP。
連接是代表兩個端點之間通信的第一個層次邏輯通道。建立連接後,兩個端點之間會協商連接ID。連接ID也用於識別連接,即使在較低協議層上發生更改,例如電話更改Wi-Fi或從Wi-Fi切換到移動數據。該機制稱為連接遷移,可防止重新啟動談判流和重新升級數據。
流是代表數據流的第二層邏輯通道。單個連接可以具有協商數量的流(例如8個最大值),這些流充當多路復用實體。每個流都有其自己的,生成的流ID,用於識別要傳輸的不同數據對象。當讀取所有數據或達到協議的最大數據傳輸時,流都關閉。
數據包是數據傳輸單元。數據包標頭包含有關該數據包被發送到的連接以及加密信息的信息。刪除其他傳輸信息後,剩下的是數據框架(數據包可以具有多個幀)。
框架是最小的單元,其中包含需要將端點的數據或諸如握手談判,錯誤處理等操作所必需的協議數據包進行。
遵循叉子並拉動github工作流程:
有關更多信息,請閱讀貢獻
如前所述,可以找到Quic-Transport草案。
要測試QUIC並查找其他信息,您可以訪問與Quic一起玩。
可以在Proto-Quic上找到官方的C ++源代碼。