Sometimes the connection will break on a wireless connection. This should prevent the lockup. Normally the lockup happens in the "while(client.connected())" loop and it becomes an endless loop. The loopCount variable controls the timeout. If you see a "Timeout" message on the serial monitor, the sketch would have locked up there.
int loopCount = 0;
while(client.connected()){
while(client.available()) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
client.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
loopCount = 0;
}
delay(1);
loopCount++;
if(loopCount > 10000) {
{
client.stop();
Serial.println();
Serial.println(F("Timeout"));
}
}
client.stop();
edit: I changed server.write() to client.write. You want that sent to only that client.