Are you sure this is what you want?
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
// if client.connected (not available), it reads, and you are not ignoring -1 (255)
char c = client.read(); //gets byte from ethernet buffer or -1 (nothing available)
This replaces all that. It reads only if characters are available, then closes the connection after the server does. Maybe it is just me...
while (client.connected()) {
while (client.available()) {
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
}
client.stop();
edit: Since I haven't mentioned this in a while, I will here. While there are characters in the w5100 rx buffer (client.available() > 0), the connection will not close. There is no sense checking client.connected() while client.available().