facebook pixel מדריך: ספריה - Ethernet - פונקציית ()Server.available - www.4project.co.il
Main logo www.4project.co.il
כל הרכיבים לפרוייקט שלכם
עגלת קניות

העגלה ריקה

לקוחות נכבדים, אלה שעות הפעילות של המחסן במהלך יום העצמאות:
ביום הזכרון/ערב עצמאות (יום שני 13/05) - המחסן סגור
יום עצמאות (יום שלישי 14/05) - המחסן סגור
נחזור לפעילות רגילה ביום רביעי 15/05
יום עצמאות שמח (עד כמה שאפשר).

ספריה - Ethernet - פונקציית ()Server.available


2022-06-14 12:59:12
פונקציית ()Server.available מחזירה אובייקט ממחלקת Client שמחובר לשרת ויש לו נתונים לקריאה. החיבור נשמר גם אם האובייקט יוצא מטווח של בלוק הקוד. אפשר לסגור את החיבור ע"י קריאה לפונקציה ()client.stop.


תחביר

קוד: בחר הכל
server.available();

פרמטרים:
אין.

הפונקציה מחזירה אובייקט של מחלקת Client. אם אין חיבורים שאפשר לקרוא מהם נתונים, אפשר להשוות את האובייקט המוחזר ל-false בפקודת if (ראו את הדוגמה בהמשך).


דוגמה

קוד: בחר הכל
#include <Ethernet.h>
#include <SPI.h>

// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
//the IP address for the shield:
byte ip[] = { 10, 0, 0, 177 };   
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 0, 0 };


// telnet defaults to port 23
EthernetServer server = EthernetServer(23);

void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);

  // start listening for clients
  server.begin();
}

void loop()
{
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    server.write(client.read());
  }
}



ראו גם:

()Stream.available
Ethernet

פירוט שפת תכנות לסביבת Arduino


עמוד זה הוא תרגום של ()Server.available לפי רישיון Creative Commons Attribution-ShareAlike 3.0.