Fixed error caused by unnecessary reopening of listening socket. Extracted packet retransmit logic to separate function. Added robust implementation for sending data Closes https://github.com/espressif/esp-idf/pull/3597