diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 8a997fa..850c432 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -264,6 +264,9 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ tcp_arg(pcb, this); tcp_err(pcb, &_s_error); size_t err = tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected); + if (err != ERR_OK){ + tcp_close(pcb); + } return (ERR_OK == err); }