WriteAsync doesn't always send data to all connected clients

I am making an application that has a TCP client that listens for messages from a TCP server, then puts those messages in a queue, then sends all of the queued messages to the connected TCP clients of the server started. The application is working, but sometimes WriteAsync doesn't send the same amount of messages to all clients. Any ideas of what the issues is, and also what can I improve on in this code? https://hastebin.com/fejosepufi.csharp Thanks
Hastebin: Send and Save Text or Code Snippets for Free | Toptal®
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
12 Replies
Cutter
Cutter2y ago
Are you checking the logs for any errors?
Determinism
Determinism2y ago
There are no errors, if I step through it in debug, all of the messages are sent If I run it without breakpoints, the problem occurs
Cutter
Cutter2y ago
have you checked any receive errors?
Determinism
Determinism2y ago
Ah, it looks to be combining the messages
Cutter
Cutter2y ago
Clap
Determinism
Determinism2y ago
Any idea on how I could prevent that?
Cutter
Cutter2y ago
idk i havent read through your code properly site and read how you are sending and recieving
Determinism
Determinism2y ago
Still seems strange as some clients receive 3 messages if sent 3 and other only receives 2
Cutter
Cutter2y ago
var bytesMessage = new byte[5000];
count = await stream.ReadAsync(bytesMessage, cancellationToken);
var bytesReceived = new byte[count + 300];
Buffer.BlockCopy(bytesMessage, 0, bytesReceived, 0, count + 40);

Log.Information($"Message size is {count}, bytes read is {bytesReceived.Length}");
var bytesMessage = new byte[5000];
count = await stream.ReadAsync(bytesMessage, cancellationToken);
var bytesReceived = new byte[count + 300];
Buffer.BlockCopy(bytesMessage, 0, bytesReceived, 0, count + 40);

Log.Information($"Message size is {count}, bytes read is {bytesReceived.Length}");
is this not just adding the message into the same array? so you'd need to determine how big the message being sent is somehow
Determinism
Determinism2y ago
True, so I only read in a certain amount of bytes, then can cut it off
Cutter
Cutter2y ago
yea
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View