I use a TCP socket via localhost to pass data between my C#/Mono program and a Python script, on Raspbian. The data is about 64k bytes. The problem is that not all bytes are sent. The maximum number of bytes sent is 49152. I expect them to arrive in a single packet.
My code:
tcpListener = new TcpListener(ip, port);
tcpListener.Start();
tcpClient = tcpListener.AcceptTcpClient();
tcpClient.SendBufferSize = 1000000;
tcpClient.ReceiveBufferSize = 1000000;
networkStream = tcpClient.GetStream();
I've tried both of the following methods to write data, but neither send all bytes.
tcpClient.Client.Send(byteArray, byteArray.Length, SocketFlags.None);
// OR
while (!networkStream.CanWrite)
{
Thread.Sleep(50);
}
networkStream.Write(byteArray, 0, size);
Currently I use two successive transmissions to send the data to the script.
Is this a Mono bug? Or am I doing something wrong here?