In Android devices, if you want to keep the WiFi connected all the time, even if the screen gets locked, you have to go at:
Settings / Wireles & Network / Wi-Fi settings
then tap on
and finally, change the “Wi-Fi sleep policy“ to “Never when plugged in“