Go to settings, scroll to connections, select WiFi and in the upper right select the more button. In the drop down menu select advanced, from that menu select "Keep WiFi on during sleep" and set to Always.
It may be that your WiFi signal is weak and the connection is being dropped (could try a router rest), also under "more connection setting", there is a selection "nearby device scanning" I always thought this was only for Bluethooth devices but it may also relate to WiFi so if it off turn it on.