Go Down

Topic: WiFi library call WiFiClient::connected() code error? (Read 841 times) previous topic - next topic

liuzengqiang

The reference says that if there are still unread data with a closed connection, the connected() will return true.

http://arduino.cc/en/Reference/WiFiClientConnected

If this is the case for IDE 1.0.5 r2, then why did they remove the available() from the connected()?

From around Arduino IDE 1.0
Code: [Select]
uint8_t WiFiClient::connected() {

  if (_sock == 255) {
    return 0;
  } else {
    uint8_t s = status();

    return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
    s == FIN_WAIT_2 || s == TIME_WAIT ||
    s == SYN_SENT || s== SYN_RCVD ||
             (s == CLOSE_WAIT && !available()));
  }
}


If there is still stuff, available() returns true and return value becomes true.

New code in 1.0.5 r2:
Code: [Select]
uint8_t WiFiClient::connected() {

  if (_sock == 255) {
    return 0;
  } else {
    uint8_t s = status();

    return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
    s == FIN_WAIT_2 || s == TIME_WAIT ||
    s == SYN_SENT || s== SYN_RCVD ||
    (s == CLOSE_WAIT));
  }
}


available is removed. I have no way to test the theory that this removal creates problems. I'm supposed to report any error. I see this as a possible error or I just don't know enough. I posted the code on network board already with a related topic but thought if they want it posted on software dev. I'll do it again.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

liuzengqiang

I upgraded to IDE 1.0.5 r2 with its own wifi lib, upgraded firmware as well. Connects to servers but the sample code on this ref page will only grab one character back because the connected() quits even when there is still bytes in buffer, opposite of the ref page claim.

http://arduino.cc/en/Reference/WiFiClientConnected

The sample code on this page, when I filled in my parameters, flat out fails to get more than one or two characters from server, because it uses if not while on the available(). If I switch to while then I get everything. It's clear, ref is bad or code is bad or both.

I think the only way this may succeed is to say HTTP/1.1 and not say connection-type: close (default is keep-alive), i.e. hogging the connection while doing nothing! Of course I tried, and it "works".

Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

Go Up