diff --git a/libraries/AP_Networking/AP_Networking_port.cpp b/libraries/AP_Networking/AP_Networking_port.cpp index 832e96de1c064..d552da12bf17f 100644 --- a/libraries/AP_Networking/AP_Networking_port.cpp +++ b/libraries/AP_Networking/AP_Networking_port.cpp @@ -13,6 +13,7 @@ #include #include #include +#include extern const AP_HAL::HAL& hal; @@ -413,6 +414,14 @@ bool AP_Networking::Port::send_receive(void) WITH_SEMAPHORE(sem); writebuffer->advance(ret); active = true; + } else if (errno == ENOTCONN && + (type == NetworkPortType::TCP_CLIENT || type == NetworkPortType::TCP_SERVER)) { + // close socket and mark as disconnected, so we can reconnect with another client or when server comes back + GCS_SEND_TEXT(MAV_SEVERITY_INFO, "TCP[%u]: disconnected", unsigned(state.idx)); + sock->close(); + delete sock; + sock = nullptr; + connected = false; } }