Now I understand.
You are reusing a socket.
After a TCP socket is closed, data can still be going around and the
default behaviour is to wait for a while before reusing that socket.
The raw API does not use sockets, but the behaviour is the same. The
waiting time varies from full hosts to embedded
In other words, do another call to tcp_new() when you want to reconnect
from tcp_close() in tcp.c:
* Connection pcbs are freed if not yet connected and may not be referenced
* any more. If a connection is established (at least SYN received or in
* a closing state), the connection is closed,