Skip to content

Commit

Permalink
Fixed a bug where only a single stream can be accepted by the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vect0rZ committed Apr 23, 2020
1 parent b2522ff commit 6f01ed6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
14 changes: 14 additions & 0 deletions QuicNet.Tests.ConsoleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ static void Main(string[] args)

Console.WriteLine("Send 'Hello From Client!'");
stream.Send(Encoding.UTF8.GetBytes("Hello from Client!")); // Send Data

stream = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional); // Create a data stream
stream.Send(Encoding.UTF8.GetBytes("Hello from Client2!"));

Console.WriteLine("Waiting for message from the server");
try
{
Expand All @@ -35,6 +39,16 @@ static void Main(string[] args)
Console.WriteLine(e.Message);
}

try
{
byte[] data = stream.Receive(); // Receive from server
Console.WriteLine("Received: " + Encoding.UTF8.GetString(data));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}

Console.ReadKey();
}
}
Expand Down
11 changes: 7 additions & 4 deletions QuicNet/Connections/QuicConnection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using QuickNet.Utilities;
using QuicNet.Context;
using QuicNet.Exceptions;
using QuicNet.Infrastructure;
using QuicNet.Infrastructure.Frames;
using QuicNet.Infrastructure.PacketProcessing;
using QuicNet.Infrastructure.Packets;
Expand All @@ -20,6 +21,7 @@ public class QuicConnection
private ConnectionState _state;
private string _lastError;
private Dictionary<UInt64, QuicStream> _streams;
private NumberSpace _ns = new NumberSpace();

private PacketWireTransfer _pwt;

Expand All @@ -39,11 +41,12 @@ public class QuicConnection
/// <returns>A new stream instance or Null if the connection is terminated.</returns>
public QuicStream CreateStream(StreamType type)
{
UInt32 streamId = _ns.Get();
if (_state != ConnectionState.Open)
return null;

QuicStream stream = new QuicStream(this, new QuickNet.Utilities.StreamId(0, type));
_streams.Add(0, stream);
QuicStream stream = new QuicStream(this, new QuickNet.Utilities.StreamId(streamId, type));
_streams.Add(streamId, stream);

return stream;
}
Expand Down Expand Up @@ -114,13 +117,13 @@ private void OnStreamFrame(Frame frame)
stream.ProcessData(sf);

if ((UInt64)_streams.Count < MaxStreams)
_streams.Add(sf.StreamId.Value, stream);
_streams.Add(sf.ConvertedStreamId.Id, stream);
else
SendMaximumStreamReachedError();
}
else
{
QuicStream stream = _streams[sf.StreamId];
QuicStream stream = _streams[sf.ConvertedStreamId.Id];
stream.ProcessData(sf);
}
}
Expand Down
2 changes: 2 additions & 0 deletions QuickNet.Tests.ConsoleServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ static void Example()
Console.WriteLine("Data received: " + Encoding.UTF8.GetString(data));

c.Send(Encoding.UTF8.GetBytes("Echo!"));
c.Send(Encoding.UTF8.GetBytes("Echo2!"));
};
}
}

static void Main(string[] args)
{
Example();
return;

byte[] bytes = new VariableInteger(12345);
VariableInteger integer = bytes;
Expand Down

0 comments on commit 6f01ed6

Please sign in to comment.