Hopefully the basic bugs are out of the Arduino and Atmel code to deal with this now.
http://arduino.cc/forum/index.php/topic,68248.0.html
This is a Mega2560 with the Arduino ethernet shield.
Atmel's compiler avr-gcc v4.5.1 and Arduino-V0022 still have an ethernet problem, so if you need ethernet client.read(), stay clear for a while.
void loop()
{
int thisByte;
int thisCount;
if(client.connected())
{
thisCount = client.available();
while(thisCount > 0)
{
thisByte = client.read();
Serial.print("Available ");
Serial.println(thisCount, DEC);
Serial.println(thisByte, DEC);
thisCount = client.available();
}
// other send and processing here, but the code only gets here once.
}
else
{
// try to reconnect
}
delay(100);
}
The code stays in the "while(thisCount > 0)" loop after receiving one response from the server.
The serial prints the available as 1279, decrementing after each read down to 1024, then starting again at 1279, and returns the same string of characters over and over. If you did not notice, the range is 1279 - 1024 = 255. Anyone recognize what might cause that? Looks like it is adding/comparing an int value in "available", and decrementing a byte value in "read".
The server only sent 12 characters and I see no traffic on the ethernet router like I do with the Windows compiled version.
The same server works fine with Windows compiled code. ??
EDIT: If I disable the server (terminate the connection), the program stops working. I have a heartbeat program on pin 13, and until I reconnect, it is out.
I though it was trying to connect, but that was apparently because I reconnected with the serial IDE, and it restarts the Arduino. Then it tries to connect correctly.
I am going to start debugging in client.cpp in the ethernet library. Somewhere around here:
int Client::available() {
if (_sock != MAX_SOCK_NUM)
return W5100.getRXReceivedSize(_sock);
return 0;
}
int Client::read() {
uint8_t b;
if (!available())
return -1;
recv(_sock, &b, 1);
return b;
}
If I bitwise AND the available with 1023 (drop bit 10), it almost works.
thisCount = client.available() & 1023;