'class ESP8266WebServer' has no member named 'available'

Keep getting this "error: 'class ESP8266WebServer' has no member named 'available'

WiFiClient client = server.available();

^

exit status 1
'class ESP8266WebServer' has no member named 'available' "

When i try to compile this code, tryed to remove all lib and reinstall them no luck, tryed to use the staging board manager to.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>

const char* ssid = "........";
const char* password = "........";

ESP8266WebServer server(80);

const char* www_username = "admin";
const char* www_password = "esp8266";

int ledPin = D7;

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(D7, LOW);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if(WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("WiFi Connect Failed! Rebooting...");
    delay(1000);
    ESP.restart();
  }
  ArduinoOTA.begin();

  server.on("/", [](){
    if(!server.authenticate(www_username, www_password))
      return server.requestAuthentication();
    server.send(200, "text/plain", "Login OK");
  });
  server.begin();

  Serial.print("Open http://");
  Serial.print(WiFi.localIP());
  Serial.println("/ in your browser to see it working");
}

void loop() {
  ArduinoOTA.handle();
  server.handleClient();
  
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  while (!client.available()) {
    delay(1);
  }

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  client.flush();

  // Match the request
  if (req.indexOf("") != -10) {  //checks if you're on the main page

    if (req.indexOf("/OFF") != -1) { //checks if you clicked OFF
      digitalWrite(ledPin, LOW);
      Serial.println("You clicked OFF");
    }
    if (req.indexOf("/ON") != -1) { //checks if you clicked ON
      digitalWrite(ledPin, HIGH);
      Serial.println("You clicked ON");
    }
  }

  else {
    Serial.println("invalid request");
   client.stop();
    return;
  }

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\n";
  s += "Content-Type: text/html\r\n\r\n";
  s += "<!DOCTYPE HTML>\r\n<html>\r\n";
  s += "
<input type=\"button\" name=\"bl\" value=\"Turn LED ON \" onclick=\"location.href='/ON'\">";
  s += "


";
  s += "
<input type=\"button\" name=\"bl\" value=\"Turn LED OFF\" onclick=\"location.href='/OFF'\">";
  s += "</html>\n";

  client.flush();


  // Send the response to the client
  client.print(s);
  delay(1);


}

Uh, you're trying to use a method that doesn't exist.

Assuming we're using the same version of that library - you can search the source yourself (I just did) - there's no available method. Just like the error is telling you.

If you got that code from somewhere, it was likely written for a different version of the library.

DrAzzy:
Uh, you're trying to use a method that doesn't exist.

Assuming we're using the same version of that library - you can search the source yourself (I just did) - there's no available method. Just like the error is telling you.

Arduino/libraries/ESP8266WebServer/src/ESP8266WebServer.h at master · esp8266/Arduino · GitHub

If you got that code from somewhere, it was likely written for a different version of the library.

Iam trying to call it from ESP8266WiFi lib but cant figure out how to do that.

but cant figure out how to do that.


Can't figure out how to do what?

If you mean that you can't figure out how to call a method that does not exist, well, keep working on it.

Apparently the new library has the statement "available" included into the .cpp (line 167).
Everything should work via .handleclient.
Easier but not evident as it used to be.

Ipodjupiter:
Apparently the new library has the statement "available" included into the .cpp (line 167).
Everything should work via .handleclient.
Easier but not evident as it used to be.

The implementation of available() should be in the cpp file. The definition of the available() method MUST be in the header file (if that is where the class is defined; if the class is defined in the source file, it is junk, and I wouldn't use it on a bet).