diff --git a/QuicNet.Infrastructure/Frames/MaxDataFrame.cs b/QuicNet.Infrastructure/Frames/MaxDataFrame.cs index 142cc40..a4f9bf8 100644 --- a/QuicNet.Infrastructure/Frames/MaxDataFrame.cs +++ b/QuicNet.Infrastructure/Frames/MaxDataFrame.cs @@ -3,21 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace QuicNet.Infrastructure.Frames { public class MaxDataFrame : Frame { + /// public override byte Type => 0x10; + public VariableInteger MaximumData { get; set; } + /// public override void Decode(ByteArray array) { array.ReadByte(); MaximumData = array.ReadVariableInteger(); } + /// public override byte[] Encode() { List result = new List(); diff --git a/QuicNet.Infrastructure/Frames/PingFrame.cs b/QuicNet.Infrastructure/Frames/PingFrame.cs index 5819801..75b2074 100644 --- a/QuicNet.Infrastructure/Frames/PingFrame.cs +++ b/QuicNet.Infrastructure/Frames/PingFrame.cs @@ -3,25 +3,28 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace QuicNet.Infrastructure.Frames { + /// + /// PING frame with Type==0x01 + /// public class PingFrame : Frame { + /// public override byte Type => 0x01; + /// public override void Decode(ByteArray array) { byte type = array.ReadByte(); } + /// public override byte[] Encode() { - List data = new List(); - data.Add(Type); - - return data.ToArray(); + byte[] res = new byte[] { Type }; + return res; } } } diff --git a/QuickNet.Tests.ConsoleServer/Program.cs b/QuickNet.Tests.ConsoleServer/Program.cs index 3950895..c54b15a 100644 --- a/QuickNet.Tests.ConsoleServer/Program.cs +++ b/QuickNet.Tests.ConsoleServer/Program.cs @@ -7,11 +7,11 @@ using QuicNet.Infrastructure.PacketProcessing; using QuicNet.Infrastructure.Packets; using QuicNet.Streams; + using System; using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace QuickNet.Tests.ConsoleServer { @@ -29,17 +29,19 @@ static void ClientConnected(QuicConnection connection) static void StreamOpened(QuicStream stream) { - Console.WriteLine("Stream Opened"); + Console.WriteLine("Stream Opened. StreamID[{0}]", stream.StreamId); stream.OnStreamDataReceived += StreamDataReceived; } static void StreamDataReceived(QuicStream stream, byte[] data) { - Console.WriteLine("Stream Data Received: "); string decoded = Encoding.UTF8.GetString(data); - Console.WriteLine(decoded); + string response = "Response from server: " + decoded.ToUpperInvariant(); + + Console.WriteLine("Stream Data Received from StreamID[{0}]\r\n <-- {1}\r\n --> {2}\r\n", + stream.StreamId, decoded, response); - stream.Send(Encoding.UTF8.GetBytes("Ping back from server.")); + stream.Send(Encoding.UTF8.GetBytes(response)); } static void Example() @@ -49,7 +51,7 @@ static void Example() listener.Start(); - Console.ReadKey(); + Console.ReadLine(); } static void Main(string[] args) diff --git a/QuickNet.Utilities/StreamId.cs b/QuickNet.Utilities/StreamId.cs index 3301b18..17473b4 100644 --- a/QuickNet.Utilities/StreamId.cs +++ b/QuickNet.Utilities/StreamId.cs @@ -1,11 +1,12 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace QuickNet.Utilities { + /// + /// Stream type (Client or Server, Bi-directional or One-directional) + /// public enum StreamType { ClientBidirectional = 0x0, @@ -14,17 +15,20 @@ public enum StreamType ServerUnidirectional = 0x3 } + /// + /// Stream identifier combines actual ID and stream type + /// public class StreamId { public UInt64 Id { get; } public UInt64 IntegerValue { get; } - public StreamType Type { get; private set; } + public StreamType Type { get; } public StreamId(UInt64 id, StreamType type) { Id = id; Type = type; - IntegerValue = id << 2 | (UInt64)type; + IntegerValue = (id << 2) | (UInt64)type; } public static implicit operator byte[](StreamId id) @@ -49,7 +53,7 @@ public static implicit operator StreamId(VariableInteger integer) public static byte[] Encode(UInt64 id, StreamType type) { - UInt64 identifier = id << 2 | (UInt64)type; + UInt64 identifier = (id << 2) | (UInt64)type; byte[] result = ByteUtilities.GetBytes(identifier); @@ -68,5 +72,12 @@ public static StreamId Decode(byte[] data) return result; } + + /// + public override string ToString() + { + string res = "ID:" + Id; + return res; + } } }