WiFi unstable, goes dead temporarily at varying intervals

the only thing i can suggest is to try a different method of flushing the tcp client. might not make any difference but hey give it a go

while (client.available()) client.read();

oh and another thing.. may help may not??

and similar