@JumpMaster, if you are compiling on the web IDE then I don't believe that client.connected() will correctly return FALSE when the server disconnects. I discussed this issue here:
The fix is available for those who compile locally but not on the web IDE yet. As a temporary fix, you can set a timeout so that when you receive nothing from the server for a set time (5 secs?), you do a client.stop().