Why client.available() is needed in a TCP server code if there is if(client) ?


hello. if have simple code...:


#include <ethernet.h>
#include <spi.h>

byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};
ipaddress ip(192, 168, 1, 107);

ethernetserver server = ethernetserver(80);

void setup() {
    serial.begin(9600);
    ethernet.begin(mac, ip);
    server.begin();
}

void loop() {
    ethernetclient client = server.available();
    if(client) {
        if(client.available()) {
            char c = client.read();
            serial.print(c);
        }
    }
}



...why necessary nested ifs? aren't redundant? mean...why if(client.available()) must written if above there if(client) line?

documentation isn't clear it.

thanks lot

first have detect if client object exists. can start asking questions if it's available.

next time, use code tags please.


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Why client.available() is needed in a TCP server code if there is if(client) ?


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

ffmpeg h264_omx encoder - libomxcore.so missing. - Raspberry Pi Forums