Arm Mbed OS support forum

LPC1768, MBed-5.15.7: TCP stack doesn't receive data

I have an application that needs to receive small packets of data over TCP. I’ve built a server using altcp_tcp_new_ip_type, altcp_bind, tcp_listen, altcp_recv and friends. The server works partially ok, i.e. for a while it works perfectly and at some point after a few packets á 11 bytes it just freezes and doesn’t call my receive handler. It’s as if the TCP stack doesn’t notice incoming data. The way I’m now testing it is:

  1. Client connects to the embedded server
  2. Server accepts connection.
  3. Client sends a request containing 11 bytes of data.
  4. Server handles request and sends back 11 bytes of data.
  5. Client closes the connection.

It’s step 4 that doesn’t always work. Sometimes I can run my test client almost 10 times (each time sending one request) before the freeze, sometimes it happens after one request. The test client waits for data from the server but never gets anything. When I kill the client the socket is closed normally in both ends, so the TCP stack is not dead. After this I can try again and a few requests may work. We have seen similar behavior with other code that also reads TCP data and also when using the TCPSocket class.

A successful request/response looks like this:

The Len=11 is the 11 bytes of data. Client sends, server responds. All fine.

When it freezes it looks like this:

Packet #95 should be an ACK of the 11 bytes of data, right? But no such ACK comes. Packet #96 is 12 seconds later and it’s when I kill the client and the socket is closed normally.

Currently we’ve been using UDP for a few years for all own protocols between the embedded thing and various mobile and other clients, as TCP has been unstable like this for the entire life span of this project. UDP works fine, but does not fit into this particular need, TCP is required here.

Is there anything obvious I’m missing? Are there known bugs where the TCP stack just doesn’t handle data correctly?

Is this using lwip included with Mbed? Or some other networking stack