diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index 7a9fdc7..74a2b7a 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -265,6 +265,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); }