available() - nomadnt-iot/uHTTP GitHub Wiki

uHTTP()

Description

Populate uHTTP attributes from client request. The connection persists when the returned client object goes out of scope; you can close it by calling client.stop().

Syntax

server.available();

Parameters

None

Returns

EthernetClient object; if no Client has data available for reading, this object will evaluate to false in an if-statement.

Example

#include <SPI.h>
#include <Ethernet.h>
#include <uHTTP.h>

byte macaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
byte ip4addr[4] = {192, 168, 0, 254};

uHTTP server = uHTTP(80);

void setup(){
    Ethernet.begin(macaddr, ip4addr);

    Serial.print(F("Starting uHTTP at "));
    Serial.print(Ethernet.localIP());
    Serial.println(":80");

    server.begin();
}

void loop(){
    EthernetClient response = server.available();
    if(response){
        response.println("HTTP/1.1 200 OK");
        response.println("Content-Type: text/plain");
        response.println();
        response.println("Hello World!");
        response.stop();
    }
}
⚠️ **GitHub.com Fallback** ⚠️