esp_netif_init() returns standard esp_err_t error code (unlike tcpip_adapter init), so shall be checked for the return value
Also to make the initialization code more consistent.
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