I am not sure how this is happening, but I have a section of code that can be simplified to the following:
var tcpClient = CreateAndConnect();
var networkStream = tcpClient.GetStream();
var streamWriter = new StreamWriter( networkStream, Encoding.UTF8 );
var msg = GetMessage();
//if i write this msg directly with this code block i will get a successful response
var bytes = Encoding.UTF8.GetBytes( msg );
await networkStream.WriteAsync( bytes, 0, bytes.Length );
//if instead i write to the streamwriter and flush it fails
streamWriter.Write( msg );
streamWriter.Flush();
I have examined the packets that are sent in wireshark, and they are in fact different by 3 bytes. I dont know enough about packets to know what exactly that difference is, although i can say with certainty the complete message is in both.