2

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.

Joe
  • 51
  • 4
  • 1.6 seconds sounds about 1.59999 seconds too long. – Majenko Sep 24 '20 at 12:22
  • Are you opening the socket fresh each time you want to send? Is there a slow DNS lookup involved with that socket opening? Do you have other things in your code that will slow down the operation? – Majenko Sep 24 '20 at 12:23
  • The socket connection is opened once and left open while the read/write loop is running. I'm using a static IP address to connect to the Teensy server so there's no DNS lookup involved. – Joe Sep 24 '20 at 12:40
  • 3
    I’m voting to close this question because the problem was elsewhere. – Juraj Sep 24 '20 at 16:50

0 Answers0