-
I have the following problem: I am trying to send several byte arrays via SignalR streaming but the order as i send them is not the same order as i receive them. I am using streaming from the SignalR .Net Client to the Server with the Channel implementation. I've been tesing this with strings and everything worked. I received the streamed items in the right order. As I understand SignalR streaming it works FIFO. Is there a bug in the implementation or is this attempt wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Can you share your code? |
Beta Was this translation helpful? Give feedback.
-
I realized the described behavior when i debugged the server and when I wrote the transferred data in a file. Client:public async Task SendFile(string filePath)
{
var fileGUID = Guid.NewGuid();
var fileInfoi = new FileInfo(filePath);
var fileSize = Convert.ToInt32(fileInfoi.Length);
var bufferSize = 256;
using (FileStream source = File.OpenRead(filePath))
{
byte[] buffer = new byte[bufferSize];
var uploadChannel = Channel.CreateUnbounded<byte[]>();
await Connection.SendAsync("UploadFile", fileGUID.ToString(), fileSize, uploadChannel.Reader);
while ((source.Read(buffer, 0, buffer.Length)) > 0)
{
await uploadChannel.Writer.WriteAsync(buffer);
}
uploadChannel.Writer.Complete();
}
} Hub-Method:public async Task UploadFile(string fileId, int fileSize, ChannelReader<byte[]> uploadStream)
{
while (await uploadStream.WaitToReadAsync())
{
while (uploadStream.TryRead(out var buffer))
{
// Do something with the data
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Thank you very much! I missed the point, that while ((source.Read(buffer = new byte[bufferSize], 0, buffer.Length)) > 0)
{
await uploadChannel.Writer.WriteAsync(buffer);
} |
Beta Was this translation helpful? Give feedback.
Thank you very much!
I missed the point, that
WriteAsync(buffer)
just writes the reference into a queue. I managed to fix this with the following snipped: