EthernetServer::available()

名称

EthernetServer::available()

説明

読み取り用のデータが利用可能な、サーバに接続しているクライアントを取得する。取得したクライアントがなくなってもコネクションは持続する。EthernetClient::stop()を呼ぶことでクローズすることができる。

available()はStreamクラスを継承する。

書式

EthernetClient available();

引数

なし。

戻り値

クライアントオブジェクト。利用可能なクライアントがない場合、このオブジェクトをif文で評価すると偽(false)になる。下記の例を参照のこと。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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());
  }
}

オリジナルのページ

https://www.arduino.cc/reference/en/libraries/ethernet/server.available/

最終更新日

January 7, 2024

inserted by FC2 system