Reference Language | Libraries | Comparison | Changes
Ethernet
if(server)
Description
Indicates whether the server is listening for new clients. You can use this to detect whether server.begin()
was successful. It can also tell you when no more sockets are available to listen for more clients, because the maximum number have connected.
Syntax
if(server)
Parameters
none
Returns
whether the server is listening for new clients (bool).
Example
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 0, 0, 177);
// telnet defaults to port 23
EthernetServer server = EthernetServer(23);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// initialize the Ethernet device
Ethernet.begin(mac, ip);
// start listening for clients
server.begin();
}
void loop() {
if (server) {
Serial.println("Server is listening");
}
else {
Serial.println("Server is not listening");
}
}
Reference Home
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.