Using a socket server on a Teensy 4.1, I am sending and receiving data in a loop from a Windows socket client (WinForms C#.NET).
I am sending or receiving 530 bytes of data. In each direction, it takes approximately 1.6 seconds to read or write and I think I've narrowed this delay down to the Teensy end when either client.read() or client.write(buffer, 530) are called by using Wireshark and a stopwatch in my C#.NET code on the Windows side.
The read code on the Teensy looks like this:
byte buffer[530];
int idx = 0;
while (client.available() > 0)
{
buffer[idx] = client.read();
idx++;
}
The write code is simply a byte array of 530 elements written like so: client.write(buffer, 530);
Is this typical? If not, is there some way to reduce this bottleneck?
Update
I found the issue - it was to do with some scanning function on the I2C bus taking up processing time. Isolating the socket server code allows it to execute very fast.