Terrible latency on Teensy 4.1 with ethernet kit

nikutsuki

Member
Hello, I recently bought a Teensy 4.1 board and the ethernet kit for it, soldered everything together and the connection works.
The problem I have is the insane latency I am getting which is around 0.25 seconds for a simple echo server.
I am using the QNEthernet library for setting up an ethernet tcp server.
The teensy code.
C++:
void process_data(qn::EthernetClient &client)
{
  size_t size;
  while((size = client.available()) > 0)
  {
    size = client.read(msg, size);
    client.write(msg,size);
  }
}


Python code I use for testing the latency.
Code:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    while True:
        start_time = time.time()
       
        s.send(b"a\0")

        data = s.recv(32)
       
        end_time = time.time()
        elapsed_time = end_time - start_time
       
        print("Received:", data)
        print("Time taken:", elapsed_time, "seconds")

Edit:
Turns out you just need to add client.flush(); in the write function loop.
 
Last edited:
Back
Top