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
Cutter3y ago
Are you checking the logs for any errors?
Determinism
DeterminismOP3y 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
Cutter3y ago
have you checked any receive errors?
Determinism
DeterminismOP3y ago
Ah, it looks to be combining the messages
Cutter
Cutter3y ago
Clap
Determinism
DeterminismOP3y ago
Any idea on how I could prevent that?
Cutter
Cutter3y ago
idk i havent read through your code properly site and read how you are sending and recieving
Determinism
DeterminismOP3y ago
Still seems strange as some clients receive 3 messages if sent 3 and other only receives 2
Cutter
Cutter3y 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
DeterminismOP3y ago
True, so I only read in a certain amount of bytes, then can cut it off
Cutter
Cutter3y ago
yea
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server